use of org.apache.calcite.sql.SqlIdentifier in project flink by apache.
the class Expander method expanded.
/**
* Expands identifiers in a given SQL string, returning a {@link Expanded}.
*/
public Expanded expanded(String ori) {
final Map<SqlParserPos, SqlIdentifier> identifiers = new HashMap<>();
final Map<String, SqlIdentifier> funcNameToId = new HashMap<>();
final SqlNode oriNode = planner.parser().parse(ori);
// parse again because validation is stateful, that means the node tree was probably
// mutated.
final SqlNode validated = planner.validate(planner.parser().parse(ori));
validated.accept(new SqlBasicVisitor<Void>() {
@Override
public Void visit(SqlCall call) {
SqlOperator operator = call.getOperator();
if (operator instanceof BridgingSqlFunction) {
final SqlIdentifier functionID = ((BridgingSqlFunction) operator).getSqlIdentifier();
if (!functionID.isSimple()) {
funcNameToId.put(Util.last(functionID.names), functionID);
}
}
return super.visit(call);
}
@Override
public Void visit(SqlIdentifier identifier) {
// and we stop expanding all of them.
if (!identifier.names.get(0).startsWith("EXPR$")) {
identifiers.putIfAbsent(identifier.getParserPosition(), identifier);
}
return null;
}
});
return new Expanded(oriNode, identifiers, funcNameToId);
}
use of org.apache.calcite.sql.SqlIdentifier in project flink by apache.
the class SqlToOperationConverter method convertSqlInsert.
/**
* Convert insert into statement.
*/
private Operation convertSqlInsert(RichSqlInsert insert) {
// Get sink table name.
List<String> targetTablePath = ((SqlIdentifier) insert.getTargetTableID()).names;
// Get sink table hints.
HintStrategyTable hintStrategyTable = flinkPlanner.config().getSqlToRelConverterConfig().getHintStrategyTable();
List<RelHint> tableHints = SqlUtil.getRelHint(hintStrategyTable, insert.getTableHints());
Map<String, String> dynamicOptions = FlinkHints.getHintedOptions(tableHints);
UnresolvedIdentifier unresolvedIdentifier = UnresolvedIdentifier.of(targetTablePath);
ObjectIdentifier identifier = catalogManager.qualifyIdentifier(unresolvedIdentifier);
ContextResolvedTable contextResolvedTable = catalogManager.getTableOrError(identifier);
PlannerQueryOperation query = (PlannerQueryOperation) convertValidatedSqlNodeOrFail(flinkPlanner, catalogManager, insert.getSource());
return new SinkModifyOperation(contextResolvedTable, query, insert.getStaticPartitionKVs(), insert.isOverwrite(), dynamicOptions);
}
use of org.apache.calcite.sql.SqlIdentifier in project flink by apache.
the class SqlDescriptorOperator method deriveType.
@Override
public RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call) {
final RelDataTypeFactory typeFactory = validator.getTypeFactory();
RelDataTypeFactory.Builder builder = typeFactory.builder().kind(StructKind.PEEK_FIELDS_NO_EXPAND);
for (SqlNode node : call.getOperandList()) {
if (node instanceof SqlIdentifier) {
// we can't infer the column type, just forward the column name for now.
builder.add(((SqlIdentifier) node).getSimple(), typeFactory.createUnknownType());
} else {
throw new IllegalArgumentException("DESCRIPTOR operator only supports accepting a list of " + "identifiers that represent a list of names.");
}
}
return builder.build();
}
use of org.apache.calcite.sql.SqlIdentifier in project flink by apache.
the class FunctionCatalogOperatorTable method lookupOperatorOverloads.
@Override
public void lookupOperatorOverloads(SqlIdentifier opName, SqlFunctionCategory category, SqlSyntax syntax, List<SqlOperator> operatorList, SqlNameMatcher nameMatcher) {
if (opName.isStar()) {
return;
}
final UnresolvedIdentifier identifier = UnresolvedIdentifier.of(opName.names);
functionCatalog.lookupFunction(identifier).flatMap(resolvedFunction -> convertToSqlFunction(category, resolvedFunction)).ifPresent(operatorList::add);
}
use of org.apache.calcite.sql.SqlIdentifier in project flink by apache.
the class SqlValidatorImpl method usingNames.
/**
* Returns the set of field names in the join condition specified by USING or implicitly by
* NATURAL, de-duplicated and in order.
*/
public List<String> usingNames(SqlJoin join) {
switch(join.getConditionType()) {
case USING:
final ImmutableList.Builder<String> list = ImmutableList.builder();
final Set<String> names = catalogReader.nameMatcher().createSet();
for (SqlNode node : (SqlNodeList) join.getCondition()) {
final String name = ((SqlIdentifier) node).getSimple();
if (names.add(name)) {
list.add(name);
}
}
return list.build();
case NONE:
if (join.isNatural()) {
final RelDataType t0 = getValidatedNodeType(join.getLeft());
final RelDataType t1 = getValidatedNodeType(join.getRight());
return SqlValidatorUtil.deriveNaturalJoinColumnList(catalogReader.nameMatcher(), t0, t1);
}
}
return null;
}
Aggregations