Search in sources :

Example 81 with SqlIdentifier

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project hazelcast by hazelcast.

the class HazelcastSqlValidator method isHiddenColumn.

private boolean isHiddenColumn(SqlNode node, SelectScope scope) {
    if (!(node instanceof SqlIdentifier)) {
        return false;
    }
    SqlIdentifier identifier = (SqlIdentifier) node;
    String fieldName = extractFieldName(identifier, scope);
    if (fieldName == null) {
        return false;
    }
    SqlValidatorTable table = scope.fullyQualify(identifier).namespace.getTable();
    if (table == null) {
        return false;
    }
    HazelcastTable unwrappedTable = table.unwrap(HazelcastTable.class);
    if (unwrappedTable == null) {
        return false;
    }
    return unwrappedTable.isHidden(fieldName);
}
Also used : SqlValidatorTable(org.apache.calcite.sql.validate.SqlValidatorTable) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable)

Example 82 with SqlIdentifier

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project hazelcast by hazelcast.

the class HazelcastSqlValidator method createSourceSelectForUpdate.

@Override
protected SqlSelect createSourceSelectForUpdate(SqlUpdate update) {
    SqlNodeList selectList = new SqlNodeList(SqlParserPos.ZERO);
    Table table = extractTable((SqlIdentifier) update.getTargetTable());
    if (table != null) {
        if (table instanceof ViewTable) {
            throw QueryException.error("DML operations not supported for views");
        }
        SqlConnector connector = getJetSqlConnector(table);
        // only tables with primary keys can be updated
        if (connector.getPrimaryKey(table).isEmpty()) {
            throw QueryException.error("Cannot UPDATE " + update.getTargetTable() + ": it doesn't have a primary key");
        }
        // add all fields, even hidden ones...
        table.getFields().forEach(field -> selectList.add(new SqlIdentifier(field.getName(), SqlParserPos.ZERO)));
    }
    int ordinal = 0;
    for (SqlNode exp : update.getSourceExpressionList()) {
        // Force unique aliases to avoid a duplicate for Y with
        // SET X=Y
        String alias = SqlUtil.deriveAliasFromOrdinal(ordinal);
        selectList.add(SqlValidatorUtil.addAlias(exp, alias));
        ++ordinal;
    }
    SqlNode sourceTable = update.getTargetTable();
    if (update.getAlias() != null) {
        sourceTable = SqlValidatorUtil.addAlias(sourceTable, update.getAlias().getSimple());
    }
    return new SqlSelect(SqlParserPos.ZERO, null, selectList, sourceTable, update.getCondition(), null, null, null, null, null, null, null);
}
Also used : HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) ViewTable(com.hazelcast.jet.sql.impl.connector.virtual.ViewTable) Table(com.hazelcast.sql.impl.schema.Table) SqlValidatorTable(org.apache.calcite.sql.validate.SqlValidatorTable) SqlSelect(org.apache.calcite.sql.SqlSelect) ViewTable(com.hazelcast.jet.sql.impl.connector.virtual.ViewTable) SqlNodeList(org.apache.calcite.sql.SqlNodeList) SqlConnectorUtil.getJetSqlConnector(com.hazelcast.jet.sql.impl.connector.SqlConnectorUtil.getJetSqlConnector) SqlConnector(com.hazelcast.jet.sql.impl.connector.SqlConnector) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) SqlNode(org.apache.calcite.sql.SqlNode)

Example 83 with SqlIdentifier

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project hazelcast by hazelcast.

the class HazelcastSqlValidator method createSourceSelectForDelete.

@Override
protected SqlSelect createSourceSelectForDelete(SqlDelete delete) {
    SqlNodeList selectList = new SqlNodeList(SqlParserPos.ZERO);
    Table table = extractTable((SqlIdentifier) delete.getTargetTable());
    if (table != null) {
        if (table instanceof ViewTable) {
            throw QueryException.error("DML operations not supported for views");
        }
        SqlConnector connector = getJetSqlConnector(table);
        // We need to feed primary keys to the delete processor so that it can directly delete the records.
        // Therefore we use the primary key for the select list.
        connector.getPrimaryKey(table).forEach(name -> selectList.add(new SqlIdentifier(name, SqlParserPos.ZERO)));
        if (selectList.size() == 0) {
            throw QueryException.error("Cannot DELETE from " + delete.getTargetTable() + ": it doesn't have a primary key");
        }
    }
    SqlNode sourceTable = delete.getTargetTable();
    if (delete.getAlias() != null) {
        sourceTable = SqlValidatorUtil.addAlias(sourceTable, delete.getAlias().getSimple());
    }
    return new SqlSelect(SqlParserPos.ZERO, null, selectList, sourceTable, delete.getCondition(), null, null, null, null, null, null, null);
}
Also used : HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) ViewTable(com.hazelcast.jet.sql.impl.connector.virtual.ViewTable) Table(com.hazelcast.sql.impl.schema.Table) SqlValidatorTable(org.apache.calcite.sql.validate.SqlValidatorTable) SqlSelect(org.apache.calcite.sql.SqlSelect) ViewTable(com.hazelcast.jet.sql.impl.connector.virtual.ViewTable) SqlNodeList(org.apache.calcite.sql.SqlNodeList) SqlConnectorUtil.getJetSqlConnector(com.hazelcast.jet.sql.impl.connector.SqlConnectorUtil.getJetSqlConnector) SqlConnector(com.hazelcast.jet.sql.impl.connector.SqlConnector) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) SqlNode(org.apache.calcite.sql.SqlNode)

Example 84 with SqlIdentifier

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project hazelcast by hazelcast.

the class HazelcastDynamicTableFunction method findOperandByName.

private static SqlNode findOperandByName(String name, SqlCall call) {
    for (int i = 0; i < call.operandCount(); i++) {
        SqlCall assignment = call.operand(i);
        SqlIdentifier id = assignment.operand(1);
        if (name.equals(id.getSimple())) {
            return assignment.operand(0);
        }
    }
    return null;
}
Also used : SqlCall(org.apache.calcite.sql.SqlCall) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier)

Example 85 with SqlIdentifier

use of org.apache.beam.vendor.calcite.v1_28_0.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)

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