use of org.apache.calcite.sql.SqlBasicCall in project coral by linkedin.
the class SparkRelToSparkSqlConverter method visit.
@Override
public Result visit(Join e) {
Result result = super.visit(e);
SqlJoin joinNode = (SqlJoin) (result.node);
SqlNode rightNode = joinNode.getRight();
// If so, let's replace the JOIN node with SqlLateralJoin node, which unparses as "LATERAL VIEW".
if (rightNode instanceof SqlBasicCall && ((SqlBasicCall) rightNode).getOperator() instanceof SqlLateralViewAsOperator) {
SqlLateralJoin join = new SqlLateralJoin(POS, joinNode.getLeft(), SqlLiteral.createBoolean(false, POS), JoinType.COMMA.symbol(POS), joinNode.getRight(), JoinConditionType.NONE.symbol(POS), joinNode.getCondition(), isCorrelateRightChildOuter(joinNode.getRight()));
result = new Result(join, Expressions.list(Clause.FROM), null, null, result.aliases);
}
return result;
}
use of org.apache.calcite.sql.SqlBasicCall in project coral by linkedin.
the class ParseTreeBuilder method visitCTE.
@Override
protected SqlNode visitCTE(ASTNode node, ParseContext ctx) {
// ASTNode tree from Hive Antlr
// TOK_QUERY
// - TOK_FROM
// - TOK_INSERT
// -- TOK_DESTINATION
// -- TOK_SELECT
// - TOK_CTE <-- processed by this method visitCTE
// -- TOK_SUBQUERY
// --- TOK_QUERY
// --- LITERAL (alias of the subquery)
// -- TOK_SUBQUERY
// --- TOK_QUERY
// --- LITERAL (alias of the subquery)
// SqlNode tree expected by Calcite
// - SqlWith
// -- withList: SqlNodeList <-- returned by this method visitCTE
// --- element: SqlWithItem
// ---- id: SimpleIdentifier
// ---- columnList: SqlNodeList (column aliases - not supported by Hive)
// ---- definition: SqlSelect
// -- node: SqlSelect
ArrayList<Node> children = node.getChildren();
checkState(children != null && !children.isEmpty());
// First, visit the children to capture all their translation result (in List<SqlNode>)
// All children are expected to be translated into SqlBasicCall(definition, alias) by visitSubquery
/**
* See {@link #visitSubquery(ASTNode, ParseContext) visitSubquery} for details
*/
List<SqlNode> sqlNodeList = visitChildren(node, ctx);
// Second, translate the list of SqlBasicCall to list of SqlWithItem
List<SqlWithItem> withItemList = new ArrayList<>();
for (SqlNode sqlNode : sqlNodeList) {
SqlBasicCall call = (SqlBasicCall) sqlNode;
SqlNode definition = call.getOperandList().get(0);
SqlNode alias = call.getOperandList().get(1);
SqlWithItem withItem = new SqlWithItem(ZERO, (SqlIdentifier) alias, null, definition);
withItemList.add(withItem);
}
// Return a SqlNodeList with the contents of the withItemList
SqlNodeList result = new SqlNodeList(withItemList, ZERO);
return result;
}
use of org.apache.calcite.sql.SqlBasicCall in project calcite by apache.
the class RelToSqlConverter method visit.
public Result visit(TableFunctionScan e) {
final List<SqlNode> inputSqlNodes = new ArrayList<>();
final int inputSize = e.getInputs().size();
for (int i = 0; i < inputSize; i++) {
final Result x = visitInput(e, i);
inputSqlNodes.add(x.asStatement());
}
final Context context = tableFunctionScanContext(inputSqlNodes);
SqlNode callNode = context.toSql(null, e.getCall());
// Convert to table function call, "TABLE($function_name(xxx))"
SqlNode tableCall = new SqlBasicCall(SqlStdOperatorTable.COLLECTION_TABLE, ImmutableList.of(callNode), SqlParserPos.ZERO);
SqlNode select = new SqlSelect(SqlParserPos.ZERO, null, SqlNodeList.SINGLETON_STAR, tableCall, null, null, null, null, null, null, null, SqlNodeList.EMPTY);
return result(select, ImmutableList.of(Clause.SELECT), e, null);
}
use of org.apache.calcite.sql.SqlBasicCall in project calcite by apache.
the class RexSqlStandardConvertletTable method convertCall.
// ~ Methods ----------------------------------------------------------------
/**
* Converts a call to an operator into a {@link SqlCall} to the same
* operator.
*
* <p>Called automatically via reflection.
*
* @param converter Converter
* @param call Call
* @return Sql call
*/
@Nullable
public SqlNode convertCall(RexToSqlNodeConverter converter, RexCall call) {
if (get(call) == null) {
return null;
}
final SqlOperator op = call.getOperator();
final List<RexNode> operands = call.getOperands();
@Nullable final List<@Nullable SqlNode> exprs = convertExpressionList(converter, operands);
if (exprs == null) {
return null;
}
return new SqlBasicCall(op, exprs, SqlParserPos.ZERO);
}
use of org.apache.calcite.sql.SqlBasicCall in project calcite by apache.
the class SqlValidatorImpl method deriveConstructorType.
@Override
public RelDataType deriveConstructorType(SqlValidatorScope scope, SqlCall call, SqlFunction unresolvedConstructor, @Nullable SqlFunction resolvedConstructor, List<RelDataType> argTypes) {
SqlIdentifier sqlIdentifier = unresolvedConstructor.getSqlIdentifier();
assert sqlIdentifier != null;
RelDataType type = catalogReader.getNamedType(sqlIdentifier);
if (type == null) {
// TODO jvs 12-Feb-2005: proper type name formatting
throw newValidationError(sqlIdentifier, RESOURCE.unknownDatatypeName(sqlIdentifier.toString()));
}
if (resolvedConstructor == null) {
if (call.operandCount() > 0) {
// no user-defined constructor could be found
throw handleUnresolvedFunction(call, unresolvedConstructor, argTypes, null);
}
} else {
SqlCall testCall = resolvedConstructor.createCall(call.getParserPosition(), call.getOperandList());
RelDataType returnType = resolvedConstructor.validateOperands(this, scope, testCall);
assert type == returnType;
}
if (config.identifierExpansion()) {
if (resolvedConstructor != null) {
((SqlBasicCall) call).setOperator(resolvedConstructor);
} else {
// fake a fully-qualified call to the default constructor
((SqlBasicCall) call).setOperator(new SqlFunction(requireNonNull(type.getSqlIdentifier(), () -> "sqlIdentifier of " + type), ReturnTypes.explicit(type), null, null, null, SqlFunctionCategory.USER_DEFINED_CONSTRUCTOR));
}
}
return type;
}
Aggregations