Search in sources :

Example 1 with TableDescriptor

use of org.apache.ignite.internal.sql.engine.schema.TableDescriptor in project ignite-3 by apache.

the class IgniteSqlValidator method inferColumnList.

private SqlNodeList inferColumnList(SqlInsert call) {
    final SqlValidatorTable table = table(validatedNamespace(call, unknownType));
    if (table == null) {
        return null;
    }
    final TableDescriptor desc = table.unwrap(TableDescriptor.class);
    if (desc == null) {
        return null;
    }
    final SqlNodeList columnList = new SqlNodeList(SqlParserPos.ZERO);
    for (RelDataTypeField field : desc.insertRowType(typeFactory()).getFieldList()) {
        columnList.add(new SqlIdentifier(field.getName(), SqlParserPos.ZERO));
    }
    return columnList;
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) SqlValidatorTable(org.apache.calcite.sql.validate.SqlValidatorTable) SqlNodeList(org.apache.calcite.sql.SqlNodeList) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) TableDescriptor(org.apache.ignite.internal.sql.engine.schema.TableDescriptor)

Example 2 with TableDescriptor

use of org.apache.ignite.internal.sql.engine.schema.TableDescriptor in project ignite-3 by apache.

the class IgniteSqlValidator method validateUpdateFields.

private void validateUpdateFields(SqlUpdate call) {
    if (call.getTargetColumnList() == null) {
        return;
    }
    final SqlValidatorNamespace ns = validatedNamespace(call, unknownType);
    final SqlValidatorTable table = table(ns);
    if (table == null) {
        return;
    }
    final TableDescriptor desc = table.unwrap(TableDescriptor.class);
    if (desc == null) {
        return;
    }
    final RelDataType baseType = table.getRowType();
    final RelOptTable relOptTable = relOptTable(ns);
    for (SqlNode node : call.getTargetColumnList()) {
        SqlIdentifier id = (SqlIdentifier) node;
        RelDataTypeField target = SqlValidatorUtil.getTargetField(baseType, typeFactory(), id, getCatalogReader(), relOptTable);
        if (target == null) {
            throw newValidationError(id, RESOURCE.unknownTargetColumn(id.toString()));
        }
        if (!desc.isUpdateAllowed(relOptTable, target.getIndex())) {
            throw newValidationError(id, IgniteResource.INSTANCE.cannotUpdateField(id.toString()));
        }
    }
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) SqlValidatorTable(org.apache.calcite.sql.validate.SqlValidatorTable) RelDataType(org.apache.calcite.rel.type.RelDataType) RelOptTable(org.apache.calcite.plan.RelOptTable) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) SqlValidatorNamespace(org.apache.calcite.sql.validate.SqlValidatorNamespace) TableDescriptor(org.apache.ignite.internal.sql.engine.schema.TableDescriptor) SqlNode(org.apache.calcite.sql.SqlNode)

Aggregations

RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)2 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)2 SqlValidatorTable (org.apache.calcite.sql.validate.SqlValidatorTable)2 TableDescriptor (org.apache.ignite.internal.sql.engine.schema.TableDescriptor)2 RelOptTable (org.apache.calcite.plan.RelOptTable)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 SqlNode (org.apache.calcite.sql.SqlNode)1 SqlNodeList (org.apache.calcite.sql.SqlNodeList)1 SqlValidatorNamespace (org.apache.calcite.sql.validate.SqlValidatorNamespace)1