use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.parser.SqlParserPos in project calcite by apache.
the class SqlLiteralChainOperator method validateCall.
public void validateCall(SqlCall call, SqlValidator validator, SqlValidatorScope scope, SqlValidatorScope operandScope) {
// per the SQL std, each string fragment must be on a different line
final List<SqlNode> operandList = call.getOperandList();
for (int i = 1; i < operandList.size(); i++) {
SqlParserPos prevPos = operandList.get(i - 1).getParserPosition();
final SqlNode operand = operandList.get(i);
SqlParserPos pos = operand.getParserPosition();
if (pos.getLineNum() <= prevPos.getLineNum()) {
throw validator.newValidationError(operand, RESOURCE.stringFragsOnSameLine());
}
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.parser.SqlParserPos in project calcite by apache.
the class SqlValidatorImpl method expandStar.
private boolean expandStar(List<SqlNode> selectItems, Set<String> aliases, List<Map.Entry<String, RelDataType>> types, boolean includeSystemVars, SelectScope scope, SqlNode node) {
if (!(node instanceof SqlIdentifier)) {
return false;
}
final SqlIdentifier identifier = (SqlIdentifier) node;
if (!identifier.isStar()) {
return false;
}
final SqlParserPos startPosition = identifier.getParserPosition();
switch(identifier.names.size()) {
case 1:
for (ScopeChild child : scope.children) {
final int before = types.size();
if (child.namespace.getRowType().isDynamicStruct()) {
// don't expand star if the underneath table is dynamic.
// Treat this star as a special field in validation/conversion and
// wait until execution time to expand this star.
final SqlNode exp = new SqlIdentifier(ImmutableList.of(child.name, DynamicRecordType.DYNAMIC_STAR_PREFIX), startPosition);
addToSelectList(selectItems, aliases, types, exp, scope, includeSystemVars);
} else {
final SqlNode from = child.namespace.getNode();
final SqlValidatorNamespace fromNs = getNamespace(from, scope);
assert fromNs != null;
final RelDataType rowType = fromNs.getRowType();
for (RelDataTypeField field : rowType.getFieldList()) {
String columnName = field.getName();
// TODO: do real implicit collation here
final SqlIdentifier exp = new SqlIdentifier(ImmutableList.of(child.name, columnName), startPosition);
// Don't add expanded rolled up columns
if (!isRolledUpColumn(exp, scope)) {
addOrExpandField(selectItems, aliases, types, includeSystemVars, scope, exp, field);
}
}
}
if (child.nullable) {
for (int i = before; i < types.size(); i++) {
final Map.Entry<String, RelDataType> entry = types.get(i);
final RelDataType type = entry.getValue();
if (!type.isNullable()) {
types.set(i, Pair.of(entry.getKey(), typeFactory.createTypeWithNullability(type, true)));
}
}
}
}
return true;
default:
final SqlIdentifier prefixId = identifier.skipLast(1);
final SqlValidatorScope.ResolvedImpl resolved = new SqlValidatorScope.ResolvedImpl();
final SqlNameMatcher nameMatcher = scope.validator.catalogReader.nameMatcher();
scope.resolve(prefixId.names, nameMatcher, true, resolved);
if (resolved.count() == 0) {
// or "select r.* from e"
throw newValidationError(prefixId, RESOURCE.unknownIdentifier(prefixId.toString()));
}
final RelDataType rowType = resolved.only().rowType();
if (rowType.isDynamicStruct()) {
// don't expand star if the underneath table is dynamic.
addToSelectList(selectItems, aliases, types, prefixId.plus(DynamicRecordType.DYNAMIC_STAR_PREFIX, startPosition), scope, includeSystemVars);
} else if (rowType.isStruct()) {
for (RelDataTypeField field : rowType.getFieldList()) {
String columnName = field.getName();
// TODO: do real implicit collation here
addOrExpandField(selectItems, aliases, types, includeSystemVars, scope, prefixId.plus(columnName, startPosition), field);
}
} else {
throw newValidationError(prefixId, RESOURCE.starRequiresRecordType());
}
return true;
}
}
Aggregations