use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project flink by apache.
the class HiveParserUtils method getSqlOperator.
public static SqlOperator getSqlOperator(String funcName, SqlOperatorTable opTable, SqlFunctionCategory category) {
funcName = funcName.toLowerCase();
String[] names = funcName.split("\\.");
SqlIdentifier identifier = new SqlIdentifier(Arrays.asList(names), SqlParserPos.ZERO);
List<SqlOperator> operators = new ArrayList<>();
try {
opTable.lookupOperatorOverloads(identifier, category, SqlSyntax.FUNCTION, operators, SqlNameMatchers.withCaseSensitive(false));
} catch (Exception e) {
LOG.warn("Error trying to resolve function " + funcName, e);
}
if (operators.isEmpty()) {
return null;
} else {
return operators.get(0);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project flink by apache.
the class RichSqlHiveInsert method getPartKeyToSpec.
private static Map<SqlIdentifier, SqlProperty> getPartKeyToSpec(SqlNodeList staticSpec) {
Map<SqlIdentifier, SqlProperty> res = new HashMap<>();
if (staticSpec != null) {
for (SqlNode node : staticSpec) {
SqlProperty spec = (SqlProperty) node;
res.put(spec.getKey(), spec);
}
}
return res;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project flink by apache.
the class SqlValidatorImpl method findAllValidFunctionNames.
private static void findAllValidFunctionNames(List<String> names, SqlValidator validator, Collection<SqlMoniker> result, SqlParserPos pos) {
// a function name can only be 1 part
if (names.size() > 1) {
return;
}
for (SqlOperator op : validator.getOperatorTable().getOperatorList()) {
SqlIdentifier curOpId = new SqlIdentifier(op.getName(), pos);
final SqlCall call = validator.makeNullaryCall(curOpId);
if (call != null) {
result.add(new SqlMonikerImpl(op.getName(), SqlMonikerType.FUNCTION));
} else {
if ((op.getSyntax() == SqlSyntax.FUNCTION) || (op.getSyntax() == SqlSyntax.PREFIX)) {
if (op.getOperandTypeChecker() != null) {
String sig = op.getAllowedSignatures();
sig = sig.replace("'", "");
result.add(new SqlMonikerImpl(sig, SqlMonikerType.FUNCTION));
continue;
}
result.add(new SqlMonikerImpl(op.getName(), SqlMonikerType.FUNCTION));
}
}
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project flink by apache.
the class SqlValidatorImpl method expandSelectItem.
/**
* If <code>selectItem</code> is "*" or "TABLE.*", expands it and returns true; otherwise writes
* the unexpanded item.
*
* @param selectItem Select-list item
* @param select Containing select clause
* @param selectItems List that expanded items are written to
* @param aliases Set of aliases
* @param fields List of field names and types, in alias order
* @param includeSystemVars If true include system vars in lists
* @return Whether the node was expanded
*/
private boolean expandSelectItem(final SqlNode selectItem, SqlSelect select, RelDataType targetType, List<SqlNode> selectItems, Set<String> aliases, List<Map.Entry<String, RelDataType>> fields, final boolean includeSystemVars) {
final SelectScope scope = (SelectScope) getWhereScope(select);
if (expandStar(selectItems, aliases, fields, includeSystemVars, scope, selectItem)) {
return true;
}
// Expand the select item: fully-qualify columns, and convert
// parentheses-free functions such as LOCALTIME into explicit function
// calls.
SqlNode expanded = expandSelectExpr(selectItem, scope, select);
final String alias = deriveAlias(selectItem, aliases.size());
// If expansion has altered the natural alias, supply an explicit 'AS'.
final SqlValidatorScope selectScope = getSelectScope(select);
if (expanded != selectItem) {
String newAlias = deriveAlias(expanded, aliases.size());
if (!newAlias.equals(alias)) {
expanded = SqlStdOperatorTable.AS.createCall(selectItem.getParserPosition(), expanded, new SqlIdentifier(alias, SqlParserPos.ZERO));
deriveTypeImpl(selectScope, expanded);
}
}
selectItems.add(expanded);
aliases.add(alias);
if (expanded != null) {
inferUnknownTypes(targetType, scope, expanded);
}
final RelDataType type = deriveType(selectScope, expanded);
setValidatedNodeType(expanded, type);
fields.add(Pair.of(alias, type));
return false;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project flink by apache.
the class SqlValidatorImpl method checkRollUp.
private void checkRollUp(SqlNode grandParent, SqlNode parent, SqlNode current, SqlValidatorScope scope, String optionalClause) {
current = stripAs(current);
if (current instanceof SqlCall && !(current instanceof SqlSelect)) {
// Validate OVER separately
checkRollUpInWindow(getWindowInOver(current), scope);
current = stripOver(current);
List<SqlNode> children = ((SqlCall) stripAs(stripDot(current))).getOperandList();
for (SqlNode child : children) {
checkRollUp(parent, current, child, scope, optionalClause);
}
} else if (current instanceof SqlIdentifier) {
SqlIdentifier id = (SqlIdentifier) current;
if (!id.isStar() && isRolledUpColumn(id, scope)) {
if (!isAggregation(parent.getKind()) || !isRolledUpColumnAllowedInAgg(id, scope, (SqlCall) parent, grandParent)) {
String context = optionalClause != null ? optionalClause : parent.getKind().toString();
throw newValidationError(id, RESOURCE.rolledUpNotAllowed(deriveAlias(id, 0), context));
}
}
}
}
Aggregations