Search in sources :

Example 76 with SqlIdentifier

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);
    }
}
Also used : SqlUserDefinedFunction(org.apache.calcite.sql.validate.SqlUserDefinedFunction) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) UdfMetadata(org.apache.samza.sql.interfaces.UdfMetadata)

Example 77 with SqlIdentifier

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);
    }
}
Also used : SqlSelect(org.apache.calcite.sql.SqlSelect) SqlBasicCall(org.apache.calcite.sql.SqlBasicCall) SqlJoin(org.apache.calcite.sql.SqlJoin) ArrayList(java.util.ArrayList) SqlUnnestOperator(org.apache.calcite.sql.SqlUnnestOperator) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) SqlAsOperator(org.apache.calcite.sql.SqlAsOperator)

Example 78 with SqlIdentifier

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;
}
Also used : SqlParserPos(org.apache.calcite.sql.parser.SqlParserPos) SqlTypeFamily(org.apache.calcite.sql.type.SqlTypeFamily) ArrayList(java.util.ArrayList) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier)

Example 79 with SqlIdentifier

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);
}
Also used : DateString(org.apache.calcite.util.DateString) TimestampString(org.apache.calcite.util.TimestampString) TimeString(org.apache.calcite.util.TimeString) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier)

Example 80 with SqlIdentifier

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);
}
Also used : CalciteContextException(org.apache.calcite.runtime.CalciteContextException) ArrayList(java.util.ArrayList) SqlTesterImpl(org.apache.calcite.sql.test.SqlTesterImpl) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) SqlNode(org.apache.calcite.sql.SqlNode) Test(org.junit.Test)

Aggregations

SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)131 SqlNode (org.apache.calcite.sql.SqlNode)84 RelDataType (org.apache.calcite.rel.type.RelDataType)46 SqlNodeList (org.apache.calcite.sql.SqlNodeList)43 ArrayList (java.util.ArrayList)41 SqlCall (org.apache.calcite.sql.SqlCall)32 BitString (org.apache.calcite.util.BitString)28 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)21 SqlSelect (org.apache.calcite.sql.SqlSelect)21 SqlParserPos (org.apache.calcite.sql.parser.SqlParserPos)12 SchemaPlus (org.apache.calcite.schema.SchemaPlus)11 SqlOperator (org.apache.calcite.sql.SqlOperator)11 NlsString (org.apache.calcite.util.NlsString)11 List (java.util.List)9 Map (java.util.Map)9 RelOptTable (org.apache.calcite.plan.RelOptTable)9 RexNode (org.apache.calcite.rex.RexNode)9 AbstractSchema (org.apache.drill.exec.store.AbstractSchema)9 ImmutableList (com.google.common.collect.ImmutableList)8 RelNode (org.apache.calcite.rel.RelNode)7