Here are the examples of the java api org.apache.calcite.sql.SqlNode taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
635 Examples
19
Source : SqlConverter.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
public SqlNode validate(final SqlNode parsedNode) {
try {
SqlNode validatedNode = validator.validate(parsedNode);
return validatedNode;
} catch (RuntimeException e) {
UserException.Builder builder = UserException.validationError(e).addContext("SQL Query", sql);
if (isInnerQuery) {
builder.message("Failure validating a view your query is dependent upon.");
}
throw builder.build(logger);
}
}
19
Source : SqlConverter.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
public RelDataType getOutputType(SqlNode validatedNode) {
return validator.getValidatedNodeType(validatedNode);
}
19
Source : UnsupportedOperatorsVisitor.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
/**
* Disable multiple parreplacedions in a SELECT-CLAUSE
* If multiple parreplacedions are defined in the query,
* SqlUnsupportedException would be thrown to inform
* @param sqlSelect SELECT-CLAUSE in the query
*/
private void detectMultipleParreplacedions(SqlSelect sqlSelect) {
for (SqlNode nodeInSelectList : sqlSelect.getSelectList()) {
// If the window function is used with an alias,
// enter the first operand of AS operator
if (nodeInSelectList.getKind() == SqlKind.AS && (((SqlCall) nodeInSelectList).getOperandList().get(0).getKind() == SqlKind.OVER)) {
nodeInSelectList = ((SqlCall) nodeInSelectList).getOperandList().get(0);
}
if (nodeInSelectList.getKind() != SqlKind.OVER) {
continue;
}
// This is used to keep track of the window function which has been defined
SqlNode definedWindow = null;
SqlNode window = ((SqlCall) nodeInSelectList).operand(1);
// Parreplacedion window is referenced as a SqlIdentifier,
// which is defined in the window list
if (window instanceof SqlIdentifier) {
// Expand the SqlIdentifier as the expression defined in the window list
for (SqlNode sqlNode : sqlSelect.getWindowList()) {
if (((SqlWindow) sqlNode).getDeclName().equalsDeep(window, false)) {
window = sqlNode;
break;
}
}
replacedert !(window instanceof SqlIdentifier) : "Identifier should have been expanded as a window defined in the window list";
}
// In a SELECT-SCOPE, only a parreplacedion can be defined
if (definedWindow == null) {
definedWindow = window;
} else {
if (!definedWindow.equalsDeep(window, false)) {
unsupportedOperatorCollector.setException(SqlUnsupportedException.ExceptionType.FUNCTION, "Multiple window definitions in a single SELECT list is not currently supported \n" + "See Apache Drill JIRA: DRILL-3196");
throw new UnsupportedOperationException();
}
}
}
}
19
Source : UnsupportedOperatorsVisitor.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
private boolean containsFlatten(SqlNode sqlNode) throws UnsupportedOperationException {
return sqlNode instanceof SqlCall && ((SqlCall) sqlNode).getOperator().getName().toLowerCase().equals("flatten");
}
19
Source : UnsupportedOperatorsVisitor.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
private boolean checkDirExplorers(SqlNode sqlNode) {
final ExprFinder dirExplorersFinder = new ExprFinder(DirExplorersCondition);
sqlNode.accept(dirExplorersFinder);
return dirExplorersFinder.find();
}
19
Source : SqlShowTables.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
/**
* Sql parse tree node to represent statement:
* SHOW TABLES [{FROM | IN} db_name] [LIKE 'pattern' | WHERE expr]
*/
public clreplaced SqlShowTables extends DrillSqlCall {
private final SqlIdentifier db;
private final SqlNode likePattern;
private final SqlNode whereClause;
public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("SHOW_TABLES", SqlKind.OTHER) {
@Override
public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
return new SqlShowTables(pos, (SqlIdentifier) operands[0], operands[1], operands[2]);
}
};
public SqlShowTables(SqlParserPos pos, SqlIdentifier db, SqlNode likePattern, SqlNode whereClause) {
super(pos);
this.db = db;
this.likePattern = likePattern;
this.whereClause = whereClause;
}
@Override
public SqlOperator getOperator() {
return OPERATOR;
}
@Override
public List<SqlNode> getOperandList() {
List<SqlNode> opList = Lists.newArrayList();
opList.add(db);
opList.add(likePattern);
opList.add(whereClause);
return opList;
}
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
writer.keyword("SHOW");
writer.keyword("TABLES");
if (db != null) {
db.unparse(writer, leftPrec, rightPrec);
}
if (likePattern != null) {
writer.keyword("LIKE");
likePattern.unparse(writer, leftPrec, rightPrec);
}
if (whereClause != null) {
whereClause.unparse(writer, leftPrec, rightPrec);
}
}
@Override
public AbstractSqlHandler getSqlHandler(SqlHandlerConfig config) {
return new ShowTablesHandler(config);
}
public SqlIdentifier getDb() {
return db;
}
public SqlNode getLikePattern() {
return likePattern;
}
public SqlNode getWhereClause() {
return whereClause;
}
}
19
Source : SqlShowSchemas.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
/**
* Sql parse tree node to represent statement:
* SHOW {DATABASES | SCHEMAS} [LIKE 'pattern' | WHERE expr]
*/
public clreplaced SqlShowSchemas extends DrillSqlCall {
private final SqlNode likePattern;
private final SqlNode whereClause;
public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("SHOW_SCHEMAS", SqlKind.OTHER) {
@Override
public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
return new SqlShowSchemas(pos, operands[0], operands[1]);
}
};
public SqlShowSchemas(SqlParserPos pos, SqlNode likePattern, SqlNode whereClause) {
super(pos);
this.likePattern = likePattern;
this.whereClause = whereClause;
}
@Override
public SqlOperator getOperator() {
return OPERATOR;
}
@Override
public List<SqlNode> getOperandList() {
List<SqlNode> opList = Lists.newArrayList();
opList.add(likePattern);
opList.add(whereClause);
return opList;
}
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
writer.keyword("SHOW");
writer.keyword("SCHEMAS");
if (likePattern != null) {
writer.keyword("LIKE");
likePattern.unparse(writer, leftPrec, rightPrec);
}
if (whereClause != null) {
whereClause.unparse(writer, leftPrec, rightPrec);
}
}
@Override
public AbstractSqlHandler getSqlHandler(SqlHandlerConfig config) {
return new ShowSchemasHandler(config);
}
public SqlNode getLikePattern() {
return likePattern;
}
public SqlNode getWhereClause() {
return whereClause;
}
}
19
Source : SqlDropFunction.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
public clreplaced SqlDropFunction extends DrillSqlCall {
private final SqlNode jar;
public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("DROP_FUNCTION", SqlKind.OTHER) {
@Override
public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
return new SqlDropFunction(pos, operands[0]);
}
};
public SqlDropFunction(SqlParserPos pos, SqlNode jar) {
super(pos);
this.jar = jar;
}
@Override
public SqlOperator getOperator() {
return OPERATOR;
}
@Override
public List<SqlNode> getOperandList() {
List<SqlNode> opList = Lists.newArrayList();
opList.add(jar);
return opList;
}
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
writer.keyword("DROP");
writer.keyword("FUNCTION");
writer.keyword("USING");
writer.keyword("JAR");
jar.unparse(writer, leftPrec, rightPrec);
}
@Override
public AbstractSqlHandler getSqlHandler(SqlHandlerConfig config) {
return new DropFunctionHandler(config);
}
public SqlNode getJar() {
return jar;
}
}
19
Source : SqlDescribeTable.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
/**
* Sql parser tree node to represent statement:
* { DESCRIBE | DESC } tblname [col_name | wildcard ]
*/
public clreplaced SqlDescribeTable extends DrillSqlCall {
private final SqlIdentifier table;
private final SqlIdentifier column;
private final SqlNode columnQualifier;
public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("DESCRIBE_TABLE", SqlKind.OTHER) {
@Override
public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
return new SqlDescribeTable(pos, (SqlIdentifier) operands[0], (SqlIdentifier) operands[1], operands[2]);
}
};
public SqlDescribeTable(SqlParserPos pos, SqlIdentifier table, SqlIdentifier column, SqlNode columnQualifier) {
super(pos);
this.table = table;
this.column = column;
this.columnQualifier = columnQualifier;
}
@Override
public SqlOperator getOperator() {
return OPERATOR;
}
@Override
public List<SqlNode> getOperandList() {
List<SqlNode> opList = Lists.newArrayList();
opList.add(table);
opList.add(column);
opList.add(columnQualifier);
return opList;
}
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
writer.keyword("DESCRIBE");
writer.keyword("TABLE");
table.unparse(writer, leftPrec, rightPrec);
if (column != null) {
column.unparse(writer, leftPrec, rightPrec);
}
if (columnQualifier != null) {
columnQualifier.unparse(writer, leftPrec, rightPrec);
}
}
@Override
public AbstractSqlHandler getSqlHandler(SqlHandlerConfig config) {
return new DescribeTableHandler(config);
}
public SqlIdentifier getTable() {
return table;
}
public SqlIdentifier getColumn() {
return column;
}
public SqlNode getColumnQualifier() {
return columnQualifier;
}
}
19
Source : SqlCreateView.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
public clreplaced SqlCreateView extends DrillSqlCall {
public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("CREATE_VIEW", SqlKind.OTHER) {
@Override
public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
return new SqlCreateView(pos, (SqlIdentifier) operands[0], (SqlNodeList) operands[1], operands[2], (SqlLiteral) operands[3]);
}
};
private SqlIdentifier viewName;
private SqlNodeList fieldList;
private SqlNode query;
private boolean replaceView;
public SqlCreateView(SqlParserPos pos, SqlIdentifier viewName, SqlNodeList fieldList, SqlNode query, SqlLiteral replaceView) {
this(pos, viewName, fieldList, query, replaceView.booleanValue());
}
public SqlCreateView(SqlParserPos pos, SqlIdentifier viewName, SqlNodeList fieldList, SqlNode query, boolean replaceView) {
super(pos);
this.viewName = viewName;
this.query = query;
this.replaceView = replaceView;
this.fieldList = fieldList;
}
@Override
public SqlOperator getOperator() {
return OPERATOR;
}
@Override
public List<SqlNode> getOperandList() {
List<SqlNode> ops = Lists.newArrayList();
ops.add(viewName);
ops.add(fieldList);
ops.add(query);
ops.add(SqlLiteral.createBoolean(replaceView, SqlParserPos.ZERO));
return ops;
}
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
writer.keyword("CREATE");
if (replaceView) {
writer.keyword("OR");
writer.keyword("REPLACE");
}
writer.keyword("VIEW");
viewName.unparse(writer, leftPrec, rightPrec);
if (fieldList.size() > 0) {
SqlHandlerUtil.unparseSqlNodeList(writer, leftPrec, rightPrec, fieldList);
}
writer.keyword("AS");
query.unparse(writer, leftPrec, rightPrec);
}
@Override
public AbstractSqlHandler getSqlHandler(SqlHandlerConfig config) {
return new ViewHandler.CreateView(config);
}
public List<String> getSchemaPath() {
if (viewName.isSimple()) {
return ImmutableList.of();
}
return viewName.names.subList(0, viewName.names.size() - 1);
}
public String getName() {
if (viewName.isSimple()) {
return viewName.getSimple();
}
return viewName.names.get(viewName.names.size() - 1);
}
public List<String> getFieldNames() {
List<String> fieldNames = Lists.newArrayList();
for (SqlNode node : fieldList.getList()) {
fieldNames.add(node.toString());
}
return fieldNames;
}
public SqlNode getQuery() {
return query;
}
public boolean getReplace() {
return replaceView;
}
}
19
Source : SqlCreateTable.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
public clreplaced SqlCreateTable extends DrillSqlCall {
public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("CREATE_TABLE", SqlKind.OTHER) {
@Override
public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
Preconditions.checkArgument(operands.length == 5, "SqlCreateTable.createCall() has to get 5 operands!");
return new SqlCreateTable(pos, (SqlIdentifier) operands[0], (SqlNodeList) operands[1], (SqlNodeList) operands[2], operands[3], (SqlLiteral) operands[4]);
}
};
private final SqlIdentifier tblName;
private final SqlNodeList fieldList;
private final SqlNodeList parreplacedionColumns;
private final SqlNode query;
private final SqlLiteral isTemporary;
public SqlCreateTable(SqlParserPos pos, SqlIdentifier tblName, SqlNodeList fieldList, SqlNodeList parreplacedionColumns, SqlNode query, SqlLiteral isTemporary) {
super(pos);
this.tblName = tblName;
this.fieldList = fieldList;
this.parreplacedionColumns = parreplacedionColumns;
this.query = query;
this.isTemporary = isTemporary;
}
@Override
public SqlOperator getOperator() {
return OPERATOR;
}
@Override
public List<SqlNode> getOperandList() {
List<SqlNode> ops = Lists.newArrayList();
ops.add(tblName);
ops.add(fieldList);
ops.add(parreplacedionColumns);
ops.add(query);
ops.add(isTemporary);
return ops;
}
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
writer.keyword("CREATE");
if (isTemporary.booleanValue()) {
writer.keyword("TEMPORARY");
}
writer.keyword("TABLE");
tblName.unparse(writer, leftPrec, rightPrec);
if (fieldList.size() > 0) {
SqlHandlerUtil.unparseSqlNodeList(writer, leftPrec, rightPrec, fieldList);
}
if (parreplacedionColumns.size() > 0) {
writer.keyword("PARreplacedION BY");
SqlHandlerUtil.unparseSqlNodeList(writer, leftPrec, rightPrec, parreplacedionColumns);
}
writer.keyword("AS");
query.unparse(writer, leftPrec, rightPrec);
}
@Override
public AbstractSqlHandler getSqlHandler(SqlHandlerConfig config) {
return getSqlHandler(config, null);
}
@Override
public AbstractSqlHandler getSqlHandler(SqlHandlerConfig config, Pointer<String> textPlan) {
replacedert textPlan != null : "Create table statement should have a plan";
return new CreateTableHandler(config, textPlan);
}
public List<String> getSchemaPath() {
if (tblName.isSimple()) {
return ImmutableList.of();
}
return tblName.names.subList(0, tblName.names.size() - 1);
}
public String getName() {
if (tblName.isSimple()) {
return tblName.getSimple();
}
return tblName.names.get(tblName.names.size() - 1);
}
public List<String> getFieldNames() {
List<String> columnNames = Lists.newArrayList();
for (SqlNode node : fieldList.getList()) {
columnNames.add(node.toString());
}
return columnNames;
}
public List<String> getParreplacedionColumns() {
List<String> columnNames = Lists.newArrayList();
for (SqlNode node : parreplacedionColumns.getList()) {
columnNames.add(node.toString());
}
return columnNames;
}
public SqlNode getQuery() {
return query;
}
public boolean isTemporary() {
return isTemporary.booleanValue();
}
}
19
Source : SqlCreateFunction.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
public clreplaced SqlCreateFunction extends DrillSqlCall {
private final SqlNode jar;
public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("CREATE_FUNCTION", SqlKind.OTHER) {
@Override
public SqlCall createCall(SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) {
return new SqlCreateFunction(pos, operands[0]);
}
};
public SqlCreateFunction(SqlParserPos pos, SqlNode jar) {
super(pos);
this.jar = jar;
}
@Override
public SqlOperator getOperator() {
return OPERATOR;
}
@Override
public List<SqlNode> getOperandList() {
List<SqlNode> opList = Lists.newArrayList();
opList.add(jar);
return opList;
}
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
writer.keyword("CREATE");
writer.keyword("FUNCTION");
writer.keyword("USING");
writer.keyword("JAR");
jar.unparse(writer, leftPrec, rightPrec);
}
@Override
public AbstractSqlHandler getSqlHandler(SqlHandlerConfig config) {
return new CreateFunctionHandler(config);
}
public SqlNode getJar() {
return jar;
}
}
19
Source : DrillParserWithCompoundIdConverter.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Override
public SqlNode parseSqlStmtEof() throws Exception {
SqlNode originalSqlNode = super.parseSqlStmtEof();
return originalSqlNode.accept(createConverter());
}
19
Source : DrillParserWithCompoundIdConverter.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Override
public SqlNode parseSqlExpressionEof() throws Exception {
SqlNode originalSqlNode = super.parseSqlExpressionEof();
return originalSqlNode.accept(createConverter());
}
19
Source : DrillCompoundIdentifier.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
public SqlNode getreplacedqlNode() {
if (ids.size() == 1) {
return new SqlIdentifier(Collections.singletonList(ids.get(0).value), ids.get(0).parserPos);
}
int startIndex;
SqlNode node;
if (ids.get(1).isArray()) {
// handle everything post zero index as item operator.
startIndex = 1;
node = new //
SqlIdentifier(//
ImmutableList.of(ids.get(0).value), //
null, //
ids.get(0).parserPos, ImmutableList.of(ids.get(0).parserPos));
} else {
// handle everything post two index as item operator.
startIndex = 2;
node = new //
SqlIdentifier(//
ImmutableList.of(ids.get(0).value, ids.get(1).value), //
null, //
ids.get(0).parserPos, ImmutableList.of(ids.get(0).parserPos, ids.get(1).parserPos));
}
for (int i = startIndex; i < ids.size(); i++) {
node = ids.get(i).getNode(node);
}
return node;
}
19
Source : UseSchemaHandler.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException, IOException, ForemanSetupException {
final SqlUseSchema useSchema = unwrap(sqlNode, SqlUseSchema.clreplaced);
final String newDefaultSchemaPath = useSchema.getSchema();
context.getSession().setDefaultSchemaPath(newDefaultSchemaPath, context.getNewDefaultSchema());
return DirectPlan.createDirectPlan(context, true, String.format("Default schema changed to [%s]", context.getSession().getDefaultSchemaPath()));
}
19
Source : ExplainHandler.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
@Override
public SqlNode rewrite(SqlNode sqlNode) throws RelConversionException, ForemanSetupException {
SqlExplain node = unwrap(sqlNode, SqlExplain.clreplaced);
SqlLiteral op = node.operand(2);
SqlExplain.Depth depth = (SqlExplain.Depth) op.getValue();
if (node.getDetailLevel() != null) {
level = node.getDetailLevel();
}
switch(depth) {
case LOGICAL:
mode = ResultMode.LOGICAL;
break;
case PHYSICAL:
mode = ResultMode.PHYSICAL;
break;
default:
throw new UnsupportedOperationException("Unknown depth " + depth);
}
return node.operand(0);
}
19
Source : DefaultSqlHandler.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
protected ConvertedRelNode validateAndConvert(SqlNode sqlNode) throws ForemanSetupException, RelConversionException, ValidationException {
final SqlNode rewrittenSqlNode = rewrite(sqlNode);
final TypedSqlNode validatedTypedSqlNode = validateNode(rewrittenSqlNode);
final SqlNode validated = validatedTypedSqlNode.getSqlNode();
RelNode rel = convertToRel(validated);
rel = preprocessNode(rel);
return new ConvertedRelNode(rel, validatedTypedSqlNode.getType());
}
19
Source : DefaultSqlHandler.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
/**
* Rewrite the parse tree. Used before validating the parse tree. Useful if a particular statement needs to converted
* into another statement.
*
* @param node
* @return Rewritten sql parse tree
* @throws RelConversionException
*/
protected SqlNode rewrite(SqlNode node) throws RelConversionException, ForemanSetupException {
return node;
}
19
Source : DefaultSqlHandler.java
with Apache License 2.0
from zpochen
with Apache License 2.0
from zpochen
private RelNode convertToRel(SqlNode node) throws RelConversionException {
final RelNode convertedNode = config.getConverter().toRel(node);
log("INITIAL", convertedNode, logger, null);
return transform(PlannerType.HEP, PlannerPhase.WINDOW_REWRITE, convertedNode);
}
19
Source : UnparseUtil.java
with Apache License 2.0
from uber-archive
with Apache License 2.0
from uber-archive
UnparseUtil node(SqlNode n) {
n.unparse(writer, leftPrec, rightPrec);
return this;
}
19
Source : SqlCreateFunction.java
with Apache License 2.0
from uber-archive
with Apache License 2.0
from uber-archive
public clreplaced SqlCreateFunction extends SqlCall {
private static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("UDF", SqlKind.OTHER_DDL);
private final SqlIdentifier dbName;
private final SqlIdentifier funcName;
private final SqlNode clreplacedName;
private final SqlNodeList jarList;
public SqlCreateFunction(SqlParserPos pos, SqlIdentifier dbName, SqlIdentifier funcName, SqlNode clreplacedName, SqlNodeList jarList) {
super(pos);
this.dbName = dbName;
this.funcName = funcName;
this.clreplacedName = clreplacedName;
this.jarList = jarList;
}
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
UnparseUtil u = new UnparseUtil(writer, leftPrec, rightPrec);
u.keyword("CREATE", "FUNCTION");
if (dbName != null) {
u.node(dbName).keyword(".");
}
u.node(funcName).keyword("AS").node(clreplacedName);
if (jarList != null) {
u.keyword("USING").nodeList(jarList);
}
}
@Override
public SqlOperator getOperator() {
return OPERATOR;
}
@Override
public List<SqlNode> getOperandList() {
return Arrays.asList(dbName, funcName, clreplacedName, jarList);
}
public SqlIdentifier dbName() {
return dbName;
}
public SqlIdentifier funcName() {
return funcName;
}
public SqlNode clreplacedName() {
return clreplacedName;
}
public SqlNodeList jarList() {
return jarList;
}
}
19
Source : SqlCreateTableExtension.java
with Apache License 2.0
from rayokota
with Apache License 2.0
from rayokota
/**
* Simple test example of a CREATE TABLE statement.
*/
public clreplaced SqlCreateTableExtension extends SqlCreateTable {
public final SqlIdentifier name;
public final SqlNodeList columnList;
public final SqlNode query;
/**
* Creates a SqlCreateTable.
*/
public SqlCreateTableExtension(SqlParserPos pos, boolean replace, boolean ifNotExists, SqlIdentifier name, SqlNodeList columnList, SqlNode query) {
super(pos, replace, ifNotExists, name, columnList, query);
this.name = Objects.requireNonNull(name);
// may be null
this.columnList = columnList;
// for "CREATE TABLE ... AS query"; may be null
this.query = query;
}
}
19
Source : ExtensionDdlExecutor.java
with Apache License 2.0
from rayokota
with Apache License 2.0
from rayokota
private void addStrategy(List<io.kareldb.schema.ColumnStrategy> strategies, ColumnStrategy strategy, SqlNode expression) {
switch(strategy) {
case NULLABLE:
strategies.add(io.kareldb.schema.ColumnStrategy.NULL_STRATEGY);
break;
case NOT_NULLABLE:
strategies.add(io.kareldb.schema.ColumnStrategy.NOT_NULL_STRATEGY);
break;
case DEFAULT:
if (expression instanceof SqlLiteral) {
strategies.add(new DefaultStrategy(((SqlLiteral) expression).getValue()));
} else {
strategies.add(io.kareldb.schema.ColumnStrategy.NOT_NULL_STRATEGY);
}
break;
default:
strategies.add(io.kareldb.schema.ColumnStrategy.NOT_NULL_STRATEGY);
break;
}
}
19
Source : RexSqlStandardConvertletTable.java
with GNU General Public License v3.0
from MyCATApache
with GNU General Public License v3.0
from MyCATApache
private SqlNode[] convertExpressionList(RexToSqlNodeConverter converter, List<RexNode> nodes) {
final SqlNode[] exprs = new SqlNode[nodes.size()];
for (int i = 0; i < nodes.size(); i++) {
RexNode node = nodes.get(i);
exprs[i] = converter.convertNode(node);
if (exprs[i] == null) {
return null;
}
}
return exprs;
}
19
Source : RelToSqlConverter.java
with GNU General Public License v3.0
from MyCATApache
with GNU General Public License v3.0
from MyCATApache
private SqlCall as(SqlNode e, String alias) {
return SqlStdOperatorTable.AS.createCall(POS, e, new SqlIdentifier(alias, POS));
}
19
Source : SparkRelToSparkSqlConverter.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
/**
* Calcite's RelNode doesn't support 'OUTER' lateral views, Source: https://calcite.apache.org/docs/reference.html
* The way Coral deals with this is by creating an IF function which will simulate an outer lateral view.
*
* For Example:
* LATERAL VIEW OUTER explode(complex.c)
* will be translated to
* LATERAL VIEW explode(if(complex.c IS NOT NULL AND size(complex.c) > 0, complex.c, ARRAY (NULL)))
*
* Spark needs an explicit 'OUTER' keyword for it to consider empty arrays,
* therefore this function helps in finding out whether OUTER keyword is needed.
*
* This functions checks if a SqlNode
* - has 'if' child
* - has ARRAY(NULL) as the else result
*/
private boolean isCorrelateRightChildOuter(SqlNode rightChild) {
if (rightChild instanceof SqlBasicCall) {
List<SqlNode> operandList = ((SqlBasicCall) rightChild).getOperandList();
if (operandList.get(0) instanceof SqlBasicCall) {
SqlBasicCall ifNode = (SqlBasicCall) operandList.get(0);
if (ifNode.getOperator().getName().equals("if") && ifNode.operandCount() == 3) {
SqlBasicCall arrayNode = (SqlBasicCall) ifNode.getOperandList().get(2);
if (arrayNode.getOperator() instanceof SqlMultisetValueConstructor && arrayNode.getOperandList().get(0) instanceof SqlLiteral) {
SqlLiteral sqlLiteral = (SqlLiteral) arrayNode.getOperandList().get(0);
return sqlLiteral.getTypeName().toString().equals("NULL");
}
}
}
}
return false;
}
19
Source : SqlLateralJoin.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
public clreplaced SqlLateralJoin extends SqlJoin {
SqlLateralJoinOperator _operator;
SqlNode left;
SqlNode right;
boolean isOuter;
public SqlLateralJoin(SqlParserPos pos, SqlNode left, SqlLiteral natural, SqlLiteral joinType, SqlNode right, SqlLiteral conditionType, SqlNode condition, boolean isOuter) {
super(pos, left, natural, joinType, right, conditionType, condition);
this.left = left;
this.right = right;
this.isOuter = isOuter;
_operator = new SqlLateralJoinOperator(isOuter);
}
@Override
public SqlOperator getOperator() {
return _operator;
}
public static clreplaced SqlLateralJoinOperator extends SqlOperator {
boolean isOuter;
public SqlLateralJoinOperator(boolean isOuter) {
super("JOIN", SqlKind.JOIN, 16, true, null, null, null);
this.isOuter = isOuter;
}
@Override
public SqlSyntax getSyntax() {
return SqlSyntax.SPECIAL;
}
@Override
public void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) {
final SqlLateralJoin join = (SqlLateralJoin) call;
final SqlWriter.Frame joinFrame = writer.startList(SqlWriter.FrameTypeEnum.JOIN);
join.left.unparse(writer, leftPrec, getLeftPrec());
switch(join.getJoinType()) {
case COMMA:
writer.literal("LATERAL VIEW");
writer.setNeedWhitespace(true);
if (isOuter) {
writer.literal("OUTER");
}
break;
default:
throw Util.unexpected(join.getJoinType());
}
join.right.unparse(writer, getRightPrec(), rightPrec);
writer.endList(joinFrame);
}
}
}
19
Source : PrestoElementAtFunction.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
@Override
public ReduceResult reduceExpr(int ordinal, TokenSequence list) {
SqlNode left = list.node(ordinal - 1);
SqlNode right = list.node(ordinal + 1);
return new ReduceResult(ordinal - 1, ordinal + 2, createCall(SqlParserPos.sum(Arrays.asList(left.getParserPosition(), right.getParserPosition(), list.pos(ordinal))), left, right));
}
19
Source : ToRelConverter.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
static String nodeToStr(SqlNode sqlNode) {
RelNode relNode = converter.toRel(sqlNode);
return relToSql(relNode);
}
19
Source : ParseTreeBuilderTest.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
@Test(dataProvider = "convertSQL")
public void testConvertAndValidate(String sqlStatement) throws SqlParseException {
SqlNode sqlNode = convert(sqlStatement);
validateSql(sqlNode, sqlStatement);
}
19
Source : FuzzyUnionTest.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
@Test
public void testDeeplyNestedStructSchemaEvolution() throws TException {
String database = "fuzzy_union";
String view = "union_view_deeply_nested_struct_evolved";
SqlNode node = getFuzzyUnionView(database, view);
String expectedSql = "" + "SELECT \"a\", \"generic_project\"(\"b\", 'b') AS \"b\"\n" + "FROM \"hive\".\"fuzzy_union\".\"tablel\"\n" + "UNION ALL\n" + "SELECT *\n" + "FROM \"hive\".\"fuzzy_union\".\"tablem\"";
getRelContextProvider().getHiveSqlValidator().validate(node);
String expandedSql = nodeToStr(node);
replacedertEquals(expandedSql, expectedSql);
}
19
Source : FuzzyUnionTest.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
@Test
public void testDoubleBranchSameSchemaEvolution() throws TException {
String database = "fuzzy_union";
String view = "union_view_double_branch_evolved_same";
SqlNode node = getFuzzyUnionView(database, view);
String expectedSql = "" + "SELECT \"a\", \"generic_project\"(\"b\", 'b') AS \"b\"\n" + "FROM \"hive\".\"fuzzy_union\".\"tabled\"\n" + "UNION ALL\n" + "SELECT \"a\", \"generic_project\"(\"b\", 'b') AS \"b\"\n" + "FROM \"hive\".\"fuzzy_union\".\"tablee\"";
getRelContextProvider().getHiveSqlValidator().validate(node);
String expandedSql = nodeToStr(node);
replacedertEquals(expandedSql, expectedSql);
}
19
Source : FuzzyUnionTest.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
@Test
public void testNoSchemaEvolution() throws TException {
String database = "fuzzy_union";
String view = "union_view";
SqlNode node = getFuzzyUnionView(database, view);
String expectedSql = "" + "SELECT *\n" + "FROM \"hive\".\"fuzzy_union\".\"tablea\"\n" + "UNION ALL\n" + "SELECT *\n" + "FROM \"hive\".\"fuzzy_union\".\"tablea\"";
getRelContextProvider().getHiveSqlValidator().validate(node);
String expandedSql = nodeToStr(node);
replacedertEquals(expandedSql, expectedSql);
}
19
Source : FuzzyUnionTest.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
private SqlNode getFuzzyUnionView(String databaseName, String viewName) throws TException {
SqlNode node = viewToSqlNode(databaseName, viewName);
Table view = relContextProvider.getHiveSchema().getSubSchema(databaseName).getTable(viewName);
node.accept(new FuzzyUnionSqlRewriter(view, viewName, getRelContextProvider()));
return node;
}
19
Source : FuzzyUnionTest.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
@Test
public void testMoreThanTwoBranchesSchemaEvolution() throws TException {
String database = "fuzzy_union";
String view = "union_view_more_than_two_branches_evolved";
SqlNode node = getFuzzyUnionView(database, view);
String expectedSql = "" + "SELECT *\n" + "FROM (SELECT \"a\", \"generic_project\"(\"b\", 'b') AS \"b\"\n" + "FROM \"hive\".\"fuzzy_union\".\"tablef\"\n" + "UNION ALL\n" + "SELECT \"a\", \"generic_project\"(\"b\", 'b') AS \"b\"\n" + "FROM \"hive\".\"fuzzy_union\".\"tableg\") AS \"t\"\n" + "UNION ALL\n" + "SELECT \"a\", \"generic_project\"(\"b\", 'b') AS \"b\"\n" + "FROM \"hive\".\"fuzzy_union\".\"tablef\"";
getRelContextProvider().getHiveSqlValidator().validate(node);
String expandedSql = nodeToStr(node);
replacedertEquals(expandedSql, expectedSql);
}
19
Source : FuzzyUnionTest.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
@Test
public void testSingleBranchSchemaEvolution() throws TException {
String database = "fuzzy_union";
String view = "union_view_single_branch_evolved";
SqlNode node = getFuzzyUnionView(database, view);
String expectedSql = "" + "SELECT *\n" + "FROM \"hive\".\"fuzzy_union\".\"tableb\"\n" + "UNION ALL\n" + "SELECT \"a\", \"generic_project\"(\"b\", 'b') AS \"b\"\n" + "FROM \"hive\".\"fuzzy_union\".\"tablec\"";
getRelContextProvider().getHiveSqlValidator().validate(node);
String expandedSql = nodeToStr(node);
replacedertEquals(expandedSql, expectedSql);
}
19
Source : FuzzyUnionTest.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
@Test
public void testArrayWithStructValueSchemaEvolution() throws TException {
String database = "fuzzy_union";
String view = "union_view_array_with_struct_value_evolved";
SqlNode node = getFuzzyUnionView(database, view);
String expectedSql = "" + "SELECT \"a\", \"generic_project\"(\"b\", 'b') AS \"b\"\n" + "FROM \"hive\".\"fuzzy_union\".\"tablej\"\n" + "UNION ALL\n" + "SELECT *\n" + "FROM \"hive\".\"fuzzy_union\".\"tablek\"";
getRelContextProvider().getHiveSqlValidator().validate(node);
String expandedSql = nodeToStr(node);
replacedertEquals(expandedSql, expectedSql);
}
19
Source : FuzzyUnionTest.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
@Test
public void testNoSchemaEvolutionWithMultipleTables() throws TException {
String database = "fuzzy_union";
String view = "union_view_with_more_than_two_tables";
SqlNode node = getFuzzyUnionView(database, view);
String expectedSql = "" + "SELECT *\n" + "FROM (SELECT *\n" + "FROM \"hive\".\"fuzzy_union\".\"tablea\"\n" + "UNION ALL\n" + "SELECT *\n" + "FROM \"hive\".\"fuzzy_union\".\"tablea\") AS \"t\"\n" + "UNION ALL\n" + "SELECT *\n" + "FROM \"hive\".\"fuzzy_union\".\"tablea\"";
getRelContextProvider().getHiveSqlValidator().validate(node);
String expandedSql = nodeToStr(node);
replacedertEquals(expandedSql, expectedSql);
}
19
Source : FuzzyUnionTest.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
@Test
public void testNoSchemaEvolutionWithAlias() throws TException {
String database = "fuzzy_union";
String view = "union_view_with_alias";
SqlNode node = getFuzzyUnionView(database, view);
String expectedSql = "" + "SELECT *\n" + "FROM \"hive\".\"fuzzy_union\".\"tablea\"\n" + "UNION ALL\n" + "SELECT *\n" + "FROM \"hive\".\"fuzzy_union\".\"tablea\"";
getRelContextProvider().getHiveSqlValidator().validate(node);
String expandedSql = nodeToStr(node);
replacedertEquals(expandedSql, expectedSql);
}
19
Source : FuzzyUnionTest.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
@Test
public void testMapWithStructValueSchemaEvolution() throws TException {
String database = "fuzzy_union";
String view = "union_view_map_with_struct_value_evolved";
SqlNode node = getFuzzyUnionView(database, view);
String expectedSql = "" + "SELECT \"a\", \"generic_project\"(\"b\", 'b') AS \"b\"\n" + "FROM \"hive\".\"fuzzy_union\".\"tableh\"\n" + "UNION ALL\n" + "SELECT *\n" + "FROM \"hive\".\"fuzzy_union\".\"tablei\"";
getRelContextProvider().getHiveSqlValidator().validate(node);
String expandedSql = nodeToStr(node);
replacedertEquals(expandedSql, expectedSql);
}
19
Source : FuzzyUnionTest.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
@Test
public void testDoubleBranchDifferentSchemaEvolution() throws TException {
String database = "fuzzy_union";
String view = "union_view_double_branch_evolved_different";
SqlNode node = getFuzzyUnionView(database, view);
String expectedSql = "" + "SELECT \"a\", \"generic_project\"(\"b\", 'b') AS \"b\"\n" + "FROM \"hive\".\"fuzzy_union\".\"tablef\"\n" + "UNION ALL\n" + "SELECT \"a\", \"generic_project\"(\"b\", 'b') AS \"b\"\n" + "FROM \"hive\".\"fuzzy_union\".\"tableg\"";
getRelContextProvider().getHiveSqlValidator().validate(node);
String expandedSql = nodeToStr(node);
replacedertEquals(expandedSql, expectedSql);
}
19
Source : ParseTreeBuilder.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
@Override
protected SqlNode visitSubqueryExpr(ASTNode node, ParseContext ctx) {
ArrayList<Node> children = node.getChildren();
checkState(children.size() >= 2);
SqlOperator op = getSubQueryOp((ASTNode) node.getChildren().get(0), ctx);
SqlNode subQuery = visit((ASTNode) children.get(1), ctx);
List<SqlNode> operands = new ArrayList<>();
operands.add(subQuery);
if (children.size() == 3) {
SqlNode lhs = visit(((ASTNode) children.get(2)), ctx);
operands.add(0, lhs);
}
return new SqlBasicCall(op, operands.toArray(new SqlNode[0]), ZERO);
}
19
Source : ParseTreeBuilder.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
private SqlNode visitUnaryOperator(ASTNode node, ParseContext ctx) {
SqlNode operand = visit((ASTNode) node.getChildren().get(0), ctx);
SqlOperator operator = functionResolver.resolveUnaryOperator(node.getText());
return operator.createCall(ZERO, operand);
}
19
Source : ParseTreeBuilder.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
@Override
protected SqlNode visitSelectExpr(ASTNode node, ParseContext ctx) {
List<SqlNode> sqlNodes = visitChildren(node, ctx);
if (sqlNodes.size() == 1) {
return sqlNodes.get(0);
} else if (sqlNodes.size() == 2) {
return new SqlBasicCall(SqlStdOperatorTable.AS, sqlNodes.toArray(new SqlNode[0]), ZERO);
} else if (sqlNodes.size() == 3) {
// lateral view alias have 3 args
SqlNode[] nodes = new SqlNode[] { sqlNodes.get(0), sqlNodes.get(2), sqlNodes.get(1) };
return new SqlBasicCall(SqlStdOperatorTable.AS, nodes, ZERO);
} else {
throw new UnhandledASTTokenException(node);
}
}
19
Source : HiveToRelConverter.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
/**
* Similar to {@link #convertSql(String)} but converts hive view definition stored
* in the hive metastore to corresponding {@link RelNode} implementation.
* This sets up the initial context for resolving Dali function names using table parameters.
* @param hiveDbName hive database name
* @param hiveViewName hive view name whose definition to convert. Table name is allowed.
* @return Calcite {@link RelNode} representation of hive view definition
*/
public RelNode convertView(String hiveDbName, String hiveViewName) {
SqlNode sqlNode = getTreeBuilder().processView(hiveDbName, hiveViewName);
Table view = relContextProvider.getHiveSchema().getSubSchema(hiveDbName).getTable(hiveViewName);
if (view != null) {
sqlNode.accept(new FuzzyUnionSqlRewriter(view, hiveViewName, relContextProvider));
}
return toRel(sqlNode);
}
19
Source : HiveToRelConverter.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
/**
* Converts input Hive SQL query to Calcite {@link RelNode}.
*
* This method resolves all the database, table and field names using the catalog
* information provided by hive configuration during initialization. The input
* sql parameter should not refer to dali functions since those can not be resolved.
* The sql can, however, refer to dali views whose definitions include dali functions.
*
* @param sql Hive sql string to convert to Calcite RelNode
* @return Calcite RelNode representation of input hive sql
*/
public RelNode convertSql(String sql) {
SqlNode sqlNode = getTreeBuilder().processSql(sql);
return toRel(sqlNode);
}
19
Source : HiveSqlValidator.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
@Override
public SqlNode expand(SqlNode expr, SqlValidatorScope scope) {
if (expr instanceof SqlBasicCall && ((SqlBasicCall) expr).getOperator().equals(FunctionFieldReferenceOperator.DOT)) {
SqlBasicCall dotCall = (SqlBasicCall) expr;
if (dotCall.operand(0) instanceof SqlBasicCall) {
return expr;
}
}
return super.expand(expr, scope);
}
19
Source : FuzzyUnionSqlRewriter.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
/**
* Determines if the SqlNode is a UNION call
* @param node a given SqlNode to evaluate
* @return true if the SqlNode is a UNION call; false otherwise
*/
private boolean isUnionOperator(SqlNode node) {
return (node instanceof SqlCall) && ((SqlCall) node).getOperator().getKind() == SqlKind.UNION;
}
19
Source : HiveFunction.java
with BSD 2-Clause "Simplified" License
from linkedin
with BSD 2-Clause "Simplified" License
from linkedin
public SqlCall createCall(SqlNode function, List<SqlNode> operands, SqlLiteral qualifier) {
return sqlOperator.createCall(qualifier, ZERO, operands.toArray(new SqlNode[operands.size()]));
}
See More Examples