diff --git a/src/main/java/com/alibaba/druid/sql/dialect/hive/ast/HiveSQLObject.java b/src/main/java/com/alibaba/druid/sql/dialect/hive/ast/HiveSQLObject.java deleted file mode 100644 index de4915dd0b..0000000000 --- a/src/main/java/com/alibaba/druid/sql/dialect/hive/ast/HiveSQLObject.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.druid.sql.dialect.hive.ast; - -import com.alibaba.druid.sql.ast.SQLObject; -import com.alibaba.druid.sql.dialect.hive.visitor.HiveASTVisitor; - - -public interface HiveSQLObject extends SQLObject { - void accept0(HiveASTVisitor visitor); -} diff --git a/src/main/java/com/alibaba/druid/sql/dialect/hive/ast/HiveSQLObjectImpl.java b/src/main/java/com/alibaba/druid/sql/dialect/hive/ast/HiveSQLObjectImpl.java deleted file mode 100644 index 3c56e0a108..0000000000 --- a/src/main/java/com/alibaba/druid/sql/dialect/hive/ast/HiveSQLObjectImpl.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.druid.sql.dialect.hive.ast; - -import com.alibaba.druid.sql.ast.SQLObjectImpl; -import com.alibaba.druid.sql.dialect.hive.visitor.HiveASTVisitor; -import com.alibaba.druid.sql.visitor.SQLASTVisitor; - -public abstract class HiveSQLObjectImpl extends SQLObjectImpl implements HiveSQLObject { - - private static final long serialVersionUID = 1L; - - @Override - public void accept0(SQLASTVisitor visitor) { - if (visitor instanceof HiveASTVisitor) { - accept0((HiveASTVisitor) visitor); - } else { - throw new IllegalArgumentException("not support visitor type : " + visitor.getClass().getName()); - } - } - - public abstract void accept0(HiveASTVisitor visitor); -} diff --git a/src/main/java/com/alibaba/druid/sql/dialect/hive/ast/HiveStatement.java b/src/main/java/com/alibaba/druid/sql/dialect/hive/ast/HiveStatement.java deleted file mode 100644 index 2f6b98258d..0000000000 --- a/src/main/java/com/alibaba/druid/sql/dialect/hive/ast/HiveStatement.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.druid.sql.dialect.hive.ast; - -import com.alibaba.druid.sql.ast.SQLStatement; - -public interface HiveStatement extends SQLStatement, HiveSQLObject { - -} diff --git a/src/main/java/com/alibaba/druid/sql/dialect/hive/ast/HiveStatementImpl.java b/src/main/java/com/alibaba/druid/sql/dialect/hive/ast/HiveStatementImpl.java deleted file mode 100644 index f3e2e22b5e..0000000000 --- a/src/main/java/com/alibaba/druid/sql/dialect/hive/ast/HiveStatementImpl.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.druid.sql.dialect.hive.ast; - -public abstract class HiveStatementImpl extends HiveSQLObjectImpl implements HiveStatement { - - private static final long serialVersionUID = 1L; - -} diff --git a/src/main/java/com/alibaba/druid/sql/dialect/hive/ast/stmt/HiveCreateTableStatement.java b/src/main/java/com/alibaba/druid/sql/dialect/hive/ast/stmt/HiveCreateTableStatement.java deleted file mode 100644 index 3edba6a707..0000000000 --- a/src/main/java/com/alibaba/druid/sql/dialect/hive/ast/stmt/HiveCreateTableStatement.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.druid.sql.dialect.hive.ast.stmt; - -import com.alibaba.druid.sql.ast.SQLDataType; -import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement; -import com.alibaba.druid.sql.dialect.hive.ast.HiveSQLObjectImpl; -import com.alibaba.druid.sql.dialect.hive.ast.HiveStatement; -import com.alibaba.druid.sql.dialect.hive.visitor.HiveASTVisitor; -import com.alibaba.druid.sql.visitor.SQLASTVisitor; - -public class HiveCreateTableStatement extends SQLCreateTableStatement implements HiveStatement { - - private static final long serialVersionUID = 1L; - - private PartitionedBy partitionedBy; - - public PartitionedBy getPartitionedBy() { - return partitionedBy; - } - - public void setPartitionedBy(PartitionedBy partitionedBy) { - this.partitionedBy = partitionedBy; - } - - @Override - protected void accept0(SQLASTVisitor visitor) { - this.accept0((HiveASTVisitor) visitor); - } - - @Override - public void accept0(HiveASTVisitor visitor) { - if (visitor.visit(this)) { - this.acceptChild(visitor, tableSource); - this.acceptChild(visitor, tableElementList); - this.acceptChild(visitor, partitionedBy); - } - visitor.endVisit(this); - } - - public static class PartitionedBy extends HiveSQLObjectImpl { - - private static final long serialVersionUID = 1L; - private String name; - private SQLDataType type; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public SQLDataType getType() { - return type; - } - - public void setType(SQLDataType type) { - this.type = type; - } - - @Override - public void accept0(HiveASTVisitor visitor) { - if (visitor.visit(this)) { - acceptChild(visitor, type); - } - visitor.endVisit(this); - } - - } - -} diff --git a/src/main/java/com/alibaba/druid/sql/dialect/hive/ast/stmt/HiveShowTablesStatement.java b/src/main/java/com/alibaba/druid/sql/dialect/hive/ast/stmt/HiveShowTablesStatement.java deleted file mode 100644 index 0dd23ce9d8..0000000000 --- a/src/main/java/com/alibaba/druid/sql/dialect/hive/ast/stmt/HiveShowTablesStatement.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.druid.sql.dialect.hive.ast.stmt; - -import com.alibaba.druid.sql.ast.expr.SQLCharExpr; -import com.alibaba.druid.sql.dialect.hive.ast.HiveStatementImpl; -import com.alibaba.druid.sql.dialect.hive.visitor.HiveASTVisitor; - -public class HiveShowTablesStatement extends HiveStatementImpl { - - private static final long serialVersionUID = 1L; - private SQLCharExpr pattern; - - - public SQLCharExpr getPattern() { - return pattern; - } - - public void setPattern(SQLCharExpr pattern) { - this.pattern = pattern; - } - - @Override - public void accept0(HiveASTVisitor visitor) { - if (visitor.visit(this)) { - acceptChild(visitor, pattern); - } - visitor.endVisit(this); - } - -} diff --git a/src/main/java/com/alibaba/druid/sql/dialect/hive/parser/HiveCreateTableParser.java b/src/main/java/com/alibaba/druid/sql/dialect/hive/parser/HiveCreateTableParser.java deleted file mode 100644 index 3319d1939d..0000000000 --- a/src/main/java/com/alibaba/druid/sql/dialect/hive/parser/HiveCreateTableParser.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.druid.sql.dialect.hive.parser; - -import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement; -import com.alibaba.druid.sql.dialect.hive.ast.stmt.HiveCreateTableStatement; -import com.alibaba.druid.sql.dialect.hive.ast.stmt.HiveCreateTableStatement.PartitionedBy; -import com.alibaba.druid.sql.parser.SQLCreateTableParser; -import com.alibaba.druid.sql.parser.SQLExprParser; -import com.alibaba.druid.sql.parser.Token; - -public class HiveCreateTableParser extends SQLCreateTableParser { - - public HiveCreateTableParser(String sql){ - super(new SQLExprParser(sql)); - } - - public HiveCreateTableParser(SQLExprParser exprParser){ - super(exprParser); - } - - protected HiveCreateTableStatement newCreateStatement() { - return new HiveCreateTableStatement(); - } - - public SQLCreateTableStatement parseCrateTable(boolean acceptCreate) { - HiveCreateTableStatement stmt = (HiveCreateTableStatement) super.parseCrateTable(acceptCreate); - - if (identifierEquals("PARTITIONED")) { - lexer.nextToken(); - accept(Token.BY); - accept(Token.LPAREN); - - PartitionedBy partitionedBy = new PartitionedBy(); - partitionedBy.setName(exprParser.name().toString()); - partitionedBy.setType(exprParser.parseDataType()); - - accept(Token.RPAREN); - - stmt.setPartitionedBy(partitionedBy); - } - - return stmt; - } -} diff --git a/src/main/java/com/alibaba/druid/sql/dialect/hive/parser/HiveExprParser.java b/src/main/java/com/alibaba/druid/sql/dialect/hive/parser/HiveExprParser.java deleted file mode 100644 index 1c1fc3e891..0000000000 --- a/src/main/java/com/alibaba/druid/sql/dialect/hive/parser/HiveExprParser.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.druid.sql.dialect.hive.parser; - -import com.alibaba.druid.sql.parser.Lexer; -import com.alibaba.druid.sql.parser.SQLExprParser; - - -public class HiveExprParser extends SQLExprParser { - public HiveExprParser(String sql) { - super(new HiveLexer(sql)); - this.lexer.nextToken(); - } - - public HiveExprParser(Lexer lexer){ - super(lexer); - } -} diff --git a/src/main/java/com/alibaba/druid/sql/dialect/hive/parser/HiveLexer.java b/src/main/java/com/alibaba/druid/sql/dialect/hive/parser/HiveLexer.java deleted file mode 100644 index 2c378649b6..0000000000 --- a/src/main/java/com/alibaba/druid/sql/dialect/hive/parser/HiveLexer.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.druid.sql.dialect.hive.parser; - -import java.util.HashMap; -import java.util.Map; - -import com.alibaba.druid.sql.parser.Keywords; -import com.alibaba.druid.sql.parser.Lexer; -import com.alibaba.druid.sql.parser.NotAllowCommentException; -import com.alibaba.druid.sql.parser.Token; - -public class HiveLexer extends Lexer { - - public final static Keywords DEFAULT_HIVE_KEYWORDS; - - static { - Map map = new HashMap(); - - map.putAll(Keywords.DEFAULT_KEYWORDS.getKeywords()); - - map.put("WITH", Token.WITH); - - DEFAULT_HIVE_KEYWORDS = new Keywords(map); - } - - public HiveLexer(char[] input, int inputLength, boolean skipComment){ - super(input, inputLength, skipComment); - super.keywods = DEFAULT_HIVE_KEYWORDS; - } - - public HiveLexer(String input){ - super(input); - super.keywods = DEFAULT_HIVE_KEYWORDS; - } - - public void scanComment() { - if (ch != '/') { - throw new IllegalStateException(); - } - - mark = pos; - bufPos = 0; - scanChar(); - bufPos++; - - // /*+ */ - if (ch == '*') { - scanChar(); - bufPos++; - - while (ch == ' ') { - scanChar(); - bufPos++; - } - - boolean isHint = false; - int startHintSp = bufPos + 1; - if (ch == '+') { - isHint = true; - scanChar(); - bufPos++; - } - - for (;;) { - if (ch == '*' && charAt(pos + 1) == '/') { - bufPos += 2; - scanChar(); - scanChar(); - break; - } - - scanChar(); - bufPos++; - } - - if (isHint) { - stringVal = subString(mark + startHintSp, (bufPos - startHintSp) - 2).trim(); - token = Token.HINT; - } else { - stringVal = subString(mark, bufPos); - token = Token.MULTI_LINE_COMMENT; - } - - if (token != Token.HINT && !isAllowComment()) { - throw new NotAllowCommentException(); - } - - return; - } - - if (!isAllowComment()) { - throw new NotAllowCommentException(); - } - - if (ch == '/') { - scanChar(); - bufPos++; - - for (;;) { - if (ch == '\r') { - if (charAt(pos + 1) == '\n') { - bufPos += 2; - scanChar(); - break; - } - bufPos++; - break; - } - - if (ch == '\r') { - scanChar(); - bufPos++; - break; - } - - scanChar(); - bufPos++; - } - - stringVal = subString(mark + 1, bufPos); - token = Token.LINE_COMMENT; - return; - } - } - -} diff --git a/src/main/java/com/alibaba/druid/sql/dialect/hive/parser/HiveStatementParser.java b/src/main/java/com/alibaba/druid/sql/dialect/hive/parser/HiveStatementParser.java deleted file mode 100644 index ca6bc1ac8f..0000000000 --- a/src/main/java/com/alibaba/druid/sql/dialect/hive/parser/HiveStatementParser.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.druid.sql.dialect.hive.parser; - -import com.alibaba.druid.sql.ast.SQLStatement; -import com.alibaba.druid.sql.ast.expr.SQLCharExpr; -import com.alibaba.druid.sql.dialect.hive.ast.stmt.HiveShowTablesStatement; -import com.alibaba.druid.sql.parser.ParserException; -import com.alibaba.druid.sql.parser.SQLExprParser; -import com.alibaba.druid.sql.parser.SQLStatementParser; -import com.alibaba.druid.sql.parser.Token; - -public class HiveStatementParser extends SQLStatementParser { - - public HiveStatementParser(SQLExprParser exprParser){ - super(exprParser); - } - - public HiveStatementParser(String sql){ - super(new SQLExprParser(sql)); - } - - public HiveCreateTableParser getSQLCreateTableParser() { - return new HiveCreateTableParser(this.exprParser); - } - - public SQLStatement parseShow() { - acceptIdentifier("SHOW"); - - if (identifierEquals("TABLES")) { - lexer.nextToken(); - - HiveShowTablesStatement stmt = new HiveShowTablesStatement(); - - if (lexer.token() == Token.LITERAL_CHARS) { - stmt.setPattern((SQLCharExpr) exprParser.primary()); - } - - return stmt; - } - - throw new ParserException("TODO " + lexer.info()); - } -} diff --git a/src/main/java/com/alibaba/druid/sql/dialect/hive/visitor/HiveASTVisitor.java b/src/main/java/com/alibaba/druid/sql/dialect/hive/visitor/HiveASTVisitor.java deleted file mode 100644 index 3ab1d79567..0000000000 --- a/src/main/java/com/alibaba/druid/sql/dialect/hive/visitor/HiveASTVisitor.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.druid.sql.dialect.hive.visitor; - -import com.alibaba.druid.sql.dialect.hive.ast.stmt.HiveCreateTableStatement; -import com.alibaba.druid.sql.dialect.hive.ast.stmt.HiveShowTablesStatement; -import com.alibaba.druid.sql.visitor.SQLASTVisitor; - -public interface HiveASTVisitor extends SQLASTVisitor { - - void endVisit(HiveShowTablesStatement x); - - boolean visit(HiveShowTablesStatement x); - - void endVisit(HiveCreateTableStatement x); - - boolean visit(HiveCreateTableStatement x); - - void endVisit(HiveCreateTableStatement.PartitionedBy x); - - boolean visit(HiveCreateTableStatement.PartitionedBy x); -} diff --git a/src/main/java/com/alibaba/druid/sql/dialect/hive/visitor/HiveASTVisitorAdapter.java b/src/main/java/com/alibaba/druid/sql/dialect/hive/visitor/HiveASTVisitorAdapter.java deleted file mode 100644 index 0bacb96229..0000000000 --- a/src/main/java/com/alibaba/druid/sql/dialect/hive/visitor/HiveASTVisitorAdapter.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.druid.sql.dialect.hive.visitor; - -import com.alibaba.druid.sql.dialect.hive.ast.stmt.HiveCreateTableStatement; -import com.alibaba.druid.sql.dialect.hive.ast.stmt.HiveShowTablesStatement; -import com.alibaba.druid.sql.visitor.SQLASTVisitorAdapter; - -public class HiveASTVisitorAdapter extends SQLASTVisitorAdapter implements HiveASTVisitor { - - @Override - public void endVisit(HiveCreateTableStatement x) { - - } - - @Override - public boolean visit(HiveCreateTableStatement x) { - return true; - } - - @Override - public void endVisit(HiveCreateTableStatement.PartitionedBy x) { - - } - - @Override - public boolean visit(HiveCreateTableStatement.PartitionedBy x) { - return true; - } - - @Override - public void endVisit(HiveShowTablesStatement x) { - - } - - @Override - public boolean visit(HiveShowTablesStatement x) { - return true; - } - -} diff --git a/src/main/java/com/alibaba/druid/sql/dialect/hive/visitor/HiveOutputVisitor.java b/src/main/java/com/alibaba/druid/sql/dialect/hive/visitor/HiveOutputVisitor.java deleted file mode 100644 index 42634ef4f3..0000000000 --- a/src/main/java/com/alibaba/druid/sql/dialect/hive/visitor/HiveOutputVisitor.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.druid.sql.dialect.hive.visitor; - -import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement; -import com.alibaba.druid.sql.dialect.hive.ast.stmt.HiveCreateTableStatement; -import com.alibaba.druid.sql.dialect.hive.ast.stmt.HiveCreateTableStatement.PartitionedBy; -import com.alibaba.druid.sql.dialect.hive.ast.stmt.HiveShowTablesStatement; -import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor; - -public class HiveOutputVisitor extends SQLASTOutputVisitor implements HiveASTVisitor { - - public HiveOutputVisitor(Appendable appender){ - super(appender); - } - - @Override - public void endVisit(HiveCreateTableStatement x) { - - } - - @Override - public boolean visit(HiveCreateTableStatement x) { - visit((SQLCreateTableStatement) x); - - if (x.getPartitionedBy() != null) { - println(); - x.getPartitionedBy().accept(this); - } - return false; - } - - @Override - public void endVisit(PartitionedBy x) { - - } - - @Override - public boolean visit(PartitionedBy x) { - print("PARTITIONED BY ("); - print(x.getName()); - print(" "); - x.getType().accept(this); - print(")"); - - return false; - } - - @Override - public void endVisit(HiveShowTablesStatement x) { - - } - - @Override - public boolean visit(HiveShowTablesStatement x) { - print("SHOW TABLES"); - if (x.getPattern() != null) { - print(" "); - x.getPattern().accept(this); - } - return false; - } - -} diff --git a/src/main/java/com/alibaba/druid/sql/dialect/hive/visitor/HiveSchemaStatVisitor.java b/src/main/java/com/alibaba/druid/sql/dialect/hive/visitor/HiveSchemaStatVisitor.java deleted file mode 100644 index 398a2d8be3..0000000000 --- a/src/main/java/com/alibaba/druid/sql/dialect/hive/visitor/HiveSchemaStatVisitor.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.druid.sql.dialect.hive.visitor; - -import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement; -import com.alibaba.druid.sql.dialect.hive.ast.stmt.HiveCreateTableStatement; -import com.alibaba.druid.sql.dialect.hive.ast.stmt.HiveShowTablesStatement; -import com.alibaba.druid.sql.visitor.SchemaStatVisitor; -import com.alibaba.druid.util.JdbcUtils; - -public class HiveSchemaStatVisitor extends SchemaStatVisitor implements HiveASTVisitor { - - @Override - public String getDbType() { - return JdbcUtils.HIVE; - } - - @Override - public void endVisit(HiveCreateTableStatement x) { - - } - - @Override - public boolean visit(HiveCreateTableStatement x) { - return visit((SQLCreateTableStatement) x); - } - - @Override - public void endVisit(HiveCreateTableStatement.PartitionedBy x) { - - } - - @Override - public boolean visit(HiveCreateTableStatement.PartitionedBy x) { - return false; - } - - @Override - public void endVisit(HiveShowTablesStatement x) { - - } - - @Override - public boolean visit(HiveShowTablesStatement x) { - return false; - } -} diff --git a/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlLexer.java b/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlLexer.java index 2aa0a51458..a2dbf44073 100644 --- a/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlLexer.java +++ b/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlLexer.java @@ -61,8 +61,6 @@ public class MySqlLexer extends Lexer { } public void scanVariable() { - final char first = ch; - if (ch != '@' && ch != ':' && ch != '#' && ch != '$') { throw new SQLParseException("illegal variable"); } diff --git a/src/main/java/com/alibaba/druid/sql/parser/Lexer.java b/src/main/java/com/alibaba/druid/sql/parser/Lexer.java index 072d1ff08d..11ccfc2ce0 100644 --- a/src/main/java/com/alibaba/druid/sql/parser/Lexer.java +++ b/src/main/java/com/alibaba/druid/sql/parser/Lexer.java @@ -822,7 +822,7 @@ public class Lexer { * translation) */ public final int pos() { - return 0; + return pos; } /** diff --git a/src/test/java/com/alibaba/druid/bvt/sql/hive/HiveCreateTableTest.java b/src/test/java/com/alibaba/druid/bvt/sql/hive/HiveCreateTableTest.java deleted file mode 100644 index ee6b451625..0000000000 --- a/src/test/java/com/alibaba/druid/bvt/sql/hive/HiveCreateTableTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.druid.bvt.sql.hive; - -import java.util.List; - -import junit.framework.Assert; - -import com.alibaba.druid.sql.ast.SQLStatement; -import com.alibaba.druid.sql.dialect.hive.parser.HiveStatementParser; -import com.alibaba.druid.sql.dialect.hive.visitor.HiveSchemaStatVisitor; -import com.alibaba.druid.sql.hive.HiveTest; -import com.alibaba.druid.stat.TableStat; - -public class HiveCreateTableTest extends HiveTest { - - public void test_hive() throws Exception { - String sql = "CREATE TABLE pokes (foo INT, bar STRING);"; - - HiveStatementParser parser = new HiveStatementParser(sql); - List statementList = parser.parseStatementList(); - SQLStatement statemen = statementList.get(0); - print(statementList); - - Assert.assertEquals(1, statementList.size()); - - HiveSchemaStatVisitor visitor = new HiveSchemaStatVisitor(); - statemen.accept(visitor); - - System.out.println("Tables : " + visitor.getTables()); - System.out.println("fields : " + visitor.getColumns()); - System.out.println("coditions : " + visitor.getConditions()); - System.out.println("relationships : " + visitor.getRelationships()); - - Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("pokes"))); - - Assert.assertEquals(2, visitor.getColumns().size()); - - Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pokes", "foo"))); - Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pokes", "bar"))); - } -} diff --git a/src/test/java/com/alibaba/druid/bvt/sql/hive/HiveCreateTableTest2.java b/src/test/java/com/alibaba/druid/bvt/sql/hive/HiveCreateTableTest2.java deleted file mode 100644 index 76c1081419..0000000000 --- a/src/test/java/com/alibaba/druid/bvt/sql/hive/HiveCreateTableTest2.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.druid.bvt.sql.hive; - -import java.util.List; - -import junit.framework.Assert; - -import com.alibaba.druid.sql.ast.SQLStatement; -import com.alibaba.druid.sql.dialect.hive.parser.HiveStatementParser; -import com.alibaba.druid.sql.dialect.hive.visitor.HiveSchemaStatVisitor; -import com.alibaba.druid.sql.hive.HiveTest; -import com.alibaba.druid.stat.TableStat; - -public class HiveCreateTableTest2 extends HiveTest { - - public void test_hive() throws Exception { - String sql = "CREATE TABLE invites (foo INT, bar STRING) PARTITIONED BY (ds STRING);"; - - HiveStatementParser parser = new HiveStatementParser(sql); - List statementList = parser.parseStatementList(); - SQLStatement statemen = statementList.get(0); - print(statementList); - - Assert.assertEquals(1, statementList.size()); - - HiveSchemaStatVisitor visitor = new HiveSchemaStatVisitor(); - statemen.accept(visitor); - - System.out.println("Tables : " + visitor.getTables()); - System.out.println("fields : " + visitor.getColumns()); - System.out.println("coditions : " + visitor.getConditions()); - System.out.println("relationships : " + visitor.getRelationships()); - - Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("invites"))); - - Assert.assertEquals(2, visitor.getColumns().size()); - - Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("invites", "foo"))); - Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("invites", "bar"))); - } -} diff --git a/src/test/java/com/alibaba/druid/bvt/sql/hive/HiveSelectTest.java b/src/test/java/com/alibaba/druid/bvt/sql/hive/HiveSelectTest.java deleted file mode 100644 index edcd0a0df7..0000000000 --- a/src/test/java/com/alibaba/druid/bvt/sql/hive/HiveSelectTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.druid.bvt.sql.hive; - -import java.util.List; - -import junit.framework.Assert; - -import com.alibaba.druid.sql.ast.SQLStatement; -import com.alibaba.druid.sql.dialect.hive.parser.HiveStatementParser; -import com.alibaba.druid.sql.dialect.hive.visitor.HiveSchemaStatVisitor; -import com.alibaba.druid.sql.hive.HiveTest; -import com.alibaba.druid.stat.TableStat; - -public class HiveSelectTest extends HiveTest { - - public void test_hive() throws Exception { - String sql = "SELECT COUNT(*) FROM u_data;"; - - HiveStatementParser parser = new HiveStatementParser(sql); - List statementList = parser.parseStatementList(); - SQLStatement statemen = statementList.get(0); - print(statementList); - - Assert.assertEquals(1, statementList.size()); - - HiveSchemaStatVisitor visitor = new HiveSchemaStatVisitor(); - statemen.accept(visitor); - - System.out.println("Tables : " + visitor.getTables()); - System.out.println("fields : " + visitor.getColumns()); - System.out.println("coditions : " + visitor.getConditions()); - System.out.println("relationships : " + visitor.getRelationships()); - - Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("u_data"))); - - Assert.assertEquals(1, visitor.getColumns().size()); - Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("u_data", "*"))); - } -} diff --git a/src/test/java/com/alibaba/druid/bvt/sql/hive/HiveSelectTest2.java b/src/test/java/com/alibaba/druid/bvt/sql/hive/HiveSelectTest2.java deleted file mode 100644 index 7e738ccd38..0000000000 --- a/src/test/java/com/alibaba/druid/bvt/sql/hive/HiveSelectTest2.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.druid.bvt.sql.hive; - -import java.util.List; - -import junit.framework.Assert; - -import com.alibaba.druid.sql.ast.SQLStatement; -import com.alibaba.druid.sql.dialect.hive.parser.HiveStatementParser; -import com.alibaba.druid.sql.dialect.hive.visitor.HiveSchemaStatVisitor; -import com.alibaba.druid.sql.hive.HiveTest; -import com.alibaba.druid.stat.TableStat; - -public class HiveSelectTest2 extends HiveTest { - - public void test_hive() throws Exception { - String sql = "SELECT a.foo FROM invites a WHERE a.ds='2008-08-15';"; - - HiveStatementParser parser = new HiveStatementParser(sql); - List statementList = parser.parseStatementList(); - SQLStatement statemen = statementList.get(0); - print(statementList); - - Assert.assertEquals(1, statementList.size()); - - HiveSchemaStatVisitor visitor = new HiveSchemaStatVisitor(); - statemen.accept(visitor); - - System.out.println("Tables : " + visitor.getTables()); - System.out.println("fields : " + visitor.getColumns()); - System.out.println("coditions : " + visitor.getConditions()); - System.out.println("relationships : " + visitor.getRelationships()); - - Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("invites"))); - - Assert.assertEquals(2, visitor.getColumns().size()); - - Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("invites", "foo"))); - Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("invites", "ds"))); - } -} diff --git a/src/test/java/com/alibaba/druid/bvt/sql/hive/HiveShowTableTest.java b/src/test/java/com/alibaba/druid/bvt/sql/hive/HiveShowTableTest.java deleted file mode 100644 index b601d6eebf..0000000000 --- a/src/test/java/com/alibaba/druid/bvt/sql/hive/HiveShowTableTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.druid.bvt.sql.hive; - -import java.util.List; - -import junit.framework.Assert; - -import com.alibaba.druid.sql.ast.SQLStatement; -import com.alibaba.druid.sql.dialect.hive.parser.HiveStatementParser; -import com.alibaba.druid.sql.dialect.hive.visitor.HiveSchemaStatVisitor; -import com.alibaba.druid.sql.hive.HiveTest; - -public class HiveShowTableTest extends HiveTest { - - public void test_hive() throws Exception { - String sql = "SHOW TABLES"; - - HiveStatementParser parser = new HiveStatementParser(sql); - List statementList = parser.parseStatementList(); - SQLStatement statemen = statementList.get(0); - print(statementList); - - Assert.assertEquals(1, statementList.size()); - - HiveSchemaStatVisitor visitor = new HiveSchemaStatVisitor(); - statemen.accept(visitor); - - System.out.println("Tables : " + visitor.getTables()); - System.out.println("fields : " + visitor.getColumns()); - System.out.println("coditions : " + visitor.getConditions()); - System.out.println("relationships : " + visitor.getRelationships()); - -// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("invites"))); - - Assert.assertEquals(0, visitor.getColumns().size()); - -// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("invites", "foo"))); -// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("invites", "bar"))); - } -} diff --git a/src/test/java/com/alibaba/druid/bvt/sql/hive/HiveShowTableTest2.java b/src/test/java/com/alibaba/druid/bvt/sql/hive/HiveShowTableTest2.java deleted file mode 100644 index d31734d913..0000000000 --- a/src/test/java/com/alibaba/druid/bvt/sql/hive/HiveShowTableTest2.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.druid.bvt.sql.hive; - -import java.util.List; - -import junit.framework.Assert; - -import com.alibaba.druid.sql.ast.SQLStatement; -import com.alibaba.druid.sql.dialect.hive.parser.HiveStatementParser; -import com.alibaba.druid.sql.dialect.hive.visitor.HiveSchemaStatVisitor; -import com.alibaba.druid.sql.hive.HiveTest; - -public class HiveShowTableTest2 extends HiveTest { - - public void test_hive() throws Exception { - String sql = "SHOW TABLES '.*s';"; - - HiveStatementParser parser = new HiveStatementParser(sql); - List statementList = parser.parseStatementList(); - SQLStatement statemen = statementList.get(0); - print(statementList); - - Assert.assertEquals(1, statementList.size()); - - HiveSchemaStatVisitor visitor = new HiveSchemaStatVisitor(); - statemen.accept(visitor); - - System.out.println("Tables : " + visitor.getTables()); - System.out.println("fields : " + visitor.getColumns()); - System.out.println("coditions : " + visitor.getConditions()); - System.out.println("relationships : " + visitor.getRelationships()); - -// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("invites"))); - - Assert.assertEquals(0, visitor.getColumns().size()); - -// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("invites", "foo"))); -// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("invites", "bar"))); - } -} diff --git a/src/test/java/com/alibaba/druid/sql/hive/HiveTest.java b/src/test/java/com/alibaba/druid/sql/hive/HiveTest.java deleted file mode 100644 index 340b25071d..0000000000 --- a/src/test/java/com/alibaba/druid/sql/hive/HiveTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.druid.sql.hive; - -import java.util.List; - -import junit.framework.TestCase; - -import com.alibaba.druid.sql.ast.SQLStatement; -import com.alibaba.druid.sql.dialect.hive.visitor.HiveOutputVisitor; - -public class HiveTest extends TestCase { - - protected String output(List stmtList) { - StringBuilder out = new StringBuilder(); - HiveOutputVisitor visitor = new HiveOutputVisitor(out); - - for (SQLStatement stmt : stmtList) { - stmt.accept(visitor); - } - - return out.toString(); - } - - protected void print(List stmtList) { - String text = output(stmtList); - String outputProperty = System.getProperty("druid.output"); - if ("false".equals(outputProperty)) { - return; - } - System.out.println(text); - } -}