use of org.apache.calcite.sql.SqlIdentifier in project samza by apache.
the class SamzaSqlUdfOperatorTable method getSqlOperator.
private SqlOperator getSqlOperator(SamzaSqlScalarFunctionImpl scalarFunction, List<UdfMetadata> udfMetadataList) {
int numArguments = scalarFunction.numberOfArguments();
UdfMetadata udfMetadata = scalarFunction.getUdfMetadata();
if (udfMetadata.isDisableArgCheck()) {
return new SqlUserDefinedFunction(new SqlIdentifier(scalarFunction.getUdfName(), SqlParserPos.ZERO), o -> scalarFunction.getReturnType(o.getTypeFactory()), null, Checker.ANY_CHECKER, null, scalarFunction);
} else {
return new SqlUserDefinedFunction(new SqlIdentifier(scalarFunction.getUdfName(), SqlParserPos.ZERO), o -> scalarFunction.getReturnType(o.getTypeFactory()), null, Checker.getChecker(numArguments, numArguments, udfMetadata), null, scalarFunction);
}
}
use of org.apache.calcite.sql.SqlIdentifier in project samza by apache.
the class SamzaSqlQueryParser method getSource.
private static void getSource(SqlNode node, ArrayList<String> sourceList) {
if (node instanceof SqlJoin) {
SqlJoin joinNode = (SqlJoin) node;
ArrayList<String> sourcesLeft = new ArrayList<>();
ArrayList<String> sourcesRight = new ArrayList<>();
getSource(joinNode.getLeft(), sourcesLeft);
getSource(joinNode.getRight(), sourcesRight);
sourceList.addAll(sourcesLeft);
sourceList.addAll(sourcesRight);
} else if (node instanceof SqlIdentifier) {
sourceList.add(node.toString());
} else if (node instanceof SqlBasicCall) {
SqlBasicCall basicCall = (SqlBasicCall) node;
if (basicCall.getOperator() instanceof SqlAsOperator) {
getSource(basicCall.operand(0), sourceList);
} else if (basicCall.getOperator() instanceof SqlUnnestOperator && basicCall.operand(0) instanceof SqlSelect) {
sourceList.addAll(getSourcesFromSelectQuery(basicCall.operand(0)));
}
} else if (node instanceof SqlSelect) {
getSource(((SqlSelect) node).getFrom(), sourceList);
}
}
use of org.apache.calcite.sql.SqlIdentifier in project flink by apache.
the class HiveParserSqlFunctionConverter method getUDFInfo.
private static CalciteUDFInfo getUDFInfo(String hiveUdfName, List<RelDataType> calciteArgTypes, RelDataType calciteRetType) {
CalciteUDFInfo udfInfo = new CalciteUDFInfo();
udfInfo.udfName = hiveUdfName;
String[] nameParts = hiveUdfName.split("\\.");
if (nameParts.length > 1) {
udfInfo.identifier = new SqlIdentifier(Arrays.stream(nameParts).collect(Collectors.toList()), new SqlParserPos(0, 0));
}
udfInfo.returnTypeInference = ReturnTypes.explicit(calciteRetType);
udfInfo.operandTypeInference = InferTypes.explicit(calciteArgTypes);
List<SqlTypeFamily> typeFamily = new ArrayList<>();
for (RelDataType argType : calciteArgTypes) {
typeFamily.add(Util.first(argType.getSqlTypeName().getFamily(), SqlTypeFamily.ANY));
}
udfInfo.operandTypeChecker = OperandTypes.family(Collections.unmodifiableList(typeFamily));
return udfInfo;
}
use of org.apache.calcite.sql.SqlIdentifier in project calcite by apache.
the class SqlImplementor method addSelect.
public void addSelect(List<SqlNode> selectList, SqlNode node, RelDataType rowType) {
String name = rowType.getFieldNames().get(selectList.size());
String alias = SqlValidatorUtil.getAlias(node, -1);
if (alias == null || !alias.equals(name)) {
node = SqlStdOperatorTable.AS.createCall(POS, node, new SqlIdentifier(name, POS));
}
selectList.add(node);
}
use of org.apache.calcite.sql.SqlIdentifier in project calcite by apache.
the class SqlValidatorUtilTest method testCheckingDuplicatesWithCompoundIdentifiers.
@SuppressWarnings("resource")
@Test
public void testCheckingDuplicatesWithCompoundIdentifiers() {
final List<SqlNode> newList = new ArrayList<>(2);
newList.add(new SqlIdentifier(Arrays.asList("f0", "c0"), SqlParserPos.ZERO));
newList.add(new SqlIdentifier(Arrays.asList("f0", "c0"), SqlParserPos.ZERO));
final SqlTesterImpl tester = new SqlTesterImpl(DefaultSqlTestFactory.INSTANCE);
final SqlValidatorImpl validator = (SqlValidatorImpl) tester.getValidator();
try {
SqlValidatorUtil.checkIdentifierListForDuplicates(newList, validator.getValidationErrorFunction());
fail("expected exception");
} catch (CalciteContextException e) {
// ok
}
// should not throw
newList.set(1, new SqlIdentifier(Arrays.asList("f0", "c1"), SqlParserPos.ZERO));
SqlValidatorUtil.checkIdentifierListForDuplicates(newList, null);
}
Aggregations