use of org.apache.calcite.sql.validate.SqlValidator in project hazelcast by hazelcast.
the class WindowUtils method getOrderingColumnType.
/**
* Return the datatype of the target column referenced by the DESCRIPTOR argument.
*/
public static RelDataType getOrderingColumnType(SqlCallBinding binding, int orderingColumnParameterIndex) {
SqlNode input = binding.operand(0);
SqlCall descriptor = (SqlCall) unwrapFunctionOperand(binding.operand(orderingColumnParameterIndex));
List<SqlNode> columnIdentifiers = descriptor.getOperandList();
if (columnIdentifiers.size() != 1) {
throw SqlUtil.newContextException(descriptor.getParserPosition(), ValidatorResource.RESOURCE.mustUseSingleOrderingColumn());
}
// `descriptor` is the DESCRIPTOR call, its operand is an SqlIdentifier having the column name
SqlIdentifier orderingColumnIdentifier = (SqlIdentifier) descriptor.getOperandList().get(0);
String orderingColumnName = orderingColumnIdentifier.getSimple();
SqlValidator validator = binding.getValidator();
RelDataTypeField columnField = validator.getValidatedNodeType(input).getField(orderingColumnName, validator.getCatalogReader().nameMatcher().isCaseSensitive(), false);
if (columnField == null) {
throw SqlUtil.newContextException(descriptor.getParserPosition(), RESOURCE.unknownIdentifier(orderingColumnName));
}
return columnField.getType();
}
use of org.apache.calcite.sql.validate.SqlValidator in project hazelcast by hazelcast.
the class SqlExtendedInsert method validate.
@Override
public void validate(SqlValidator validator, SqlValidatorScope scope) {
SqlValidatorTable table0 = validator.getCatalogReader().getTable(tableNames());
if (table0 == null) {
super.validate(validator, scope);
// should have failed with "Object not found"
assert false;
}
HazelcastTable table = table0.unwrap(HazelcastTable.class);
if (getTargetColumnList() == null) {
RelDataType rowType = table.getRowType(validator.getTypeFactory());
List<SqlNode> columnListWithoutHidden = new ArrayList<>();
for (RelDataTypeField f : rowType.getFieldList()) {
if (!table.isHidden(f.getName())) {
columnListWithoutHidden.add(new SqlIdentifier(f.getName(), SqlParserPos.ZERO));
}
}
overrideColumnList = new SqlNodeList(columnListWithoutHidden, SqlParserPos.ZERO);
}
super.validate(validator, scope);
Map<String, TableField> fieldsMap = table.getTarget().getFields().stream().collect(Collectors.toMap(TableField::getName, f -> f));
for (SqlNode fieldNode : getTargetColumnList()) {
TableField field = fieldsMap.get(((SqlIdentifier) fieldNode).getSimple());
if (field instanceof MapTableField) {
QueryPath path = ((MapTableField) field).getPath();
if (path.getPath() == null && field.getType().getTypeFamily() == QueryDataTypeFamily.OBJECT) {
throw validator.newValidationError(fieldNode, RESOURCE.insertToTopLevelObject());
}
}
}
}
Aggregations