use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.parser.SqlParserPos in project drill by apache.
the class TestDrillSQLWorker method testErrorFormatting.
@Test
public void testErrorFormatting() {
String sql = "Select * from Foo\n" + "where tadadidada;\n";
validateFormattedIs(sql, new SqlParserPos(1, 2), "SQL Query: Select * from Foo\n" + " ^\n" + "where tadadidada;");
validateFormattedIs(sql, new SqlParserPos(2, 2), "SQL Query: Select * from Foo\n" + "where tadadidada;\n" + " ^");
validateFormattedIs(sql, new SqlParserPos(1, 10), "SQL Query: Select * from Foo\n" + " ^\n" + "where tadadidada;");
validateFormattedIs(sql, new SqlParserPos(-11, -10), "SQL Query: Select * from Foo\nwhere tadadidada;");
validateFormattedIs(sql, new SqlParserPos(0, 10), "SQL Query: Select * from Foo\nwhere tadadidada;");
validateFormattedIs(sql, new SqlParserPos(100, 10), "SQL Query: Select * from Foo\nwhere tadadidada;");
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.parser.SqlParserPos in project calcite by apache.
the class SqlCoalesceFunction method rewriteCall.
// ~ Methods ----------------------------------------------------------------
// override SqlOperator
public SqlNode rewriteCall(SqlValidator validator, SqlCall call) {
// check DISTINCT/ALL
validateQuantifier(validator, call);
List<SqlNode> operands = call.getOperandList();
if (operands.size() == 1) {
// No CASE needed
return operands.get(0);
}
SqlParserPos pos = call.getParserPosition();
SqlNodeList whenList = new SqlNodeList(pos);
SqlNodeList thenList = new SqlNodeList(pos);
for (SqlNode operand : Util.skipLast(operands)) {
whenList.add(SqlStdOperatorTable.IS_NOT_NULL.createCall(pos, operand));
thenList.add(SqlNode.clone(operand));
}
SqlNode elseExpr = Util.last(operands);
assert call.getFunctionQuantifier() == null;
return SqlCase.createSwitched(pos, null, whenList, thenList, elseExpr);
}
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;
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.parser.SqlParserPos in project hive by apache.
the class RexNodeExprFactory method createIntervalHourConstantExpr.
/**
* {@inheritDoc}
*/
@Override
protected RexLiteral createIntervalHourConstantExpr(String value) {
HiveIntervalDayTime v = new HiveIntervalDayTime(0, Integer.parseInt(value), 0, 0, 0);
BigDecimal secsValueBd = BigDecimal.valueOf(v.getTotalSeconds() * 1000);
BigDecimal nanosValueBd = BigDecimal.valueOf((v).getNanos(), 6);
return rexBuilder.makeIntervalLiteral(secsValueBd.add(nanosValueBd), new SqlIntervalQualifier(TimeUnit.MILLISECOND, null, new SqlParserPos(1, 1)));
}
Aggregations