use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project calcite by apache.
the class SqlTypeUtil method convertTypeToSpec.
/**
* Converts an instance of RelDataType to an instance of SqlDataTypeSpec.
*
* @param type type descriptor
* @return corresponding parse representation
*/
public static SqlDataTypeSpec convertTypeToSpec(RelDataType type) {
SqlTypeName typeName = type.getSqlTypeName();
// interval types, multiset types, etc
assert typeName != null;
SqlIdentifier typeIdentifier = new SqlIdentifier(typeName.name(), SqlParserPos.ZERO);
String charSetName = null;
if (inCharFamily(type)) {
charSetName = type.getCharset().name();
// TODO jvs 28-Dec-2004: collation
}
if (typeName.allowsScale()) {
return new SqlDataTypeSpec(typeIdentifier, type.getPrecision(), type.getScale(), charSetName, null, SqlParserPos.ZERO);
} else if (typeName.allowsPrec()) {
return new SqlDataTypeSpec(typeIdentifier, type.getPrecision(), -1, charSetName, null, SqlParserPos.ZERO);
} else {
return new SqlDataTypeSpec(typeIdentifier, -1, -1, charSetName, null, SqlParserPos.ZERO);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project calcite by apache.
the class AggChecker method visit.
public Void visit(SqlCall call) {
final SqlValidatorScope scope = scopes.peek();
if (call.getOperator().isAggregator()) {
if (distinct) {
if (scope instanceof AggregatingSelectScope) {
SqlNodeList selectList = ((SqlSelect) scope.getNode()).getSelectList();
// Check if this aggregation function is just an element in the select
for (SqlNode sqlNode : selectList) {
if (sqlNode.getKind() == SqlKind.AS) {
sqlNode = ((SqlCall) sqlNode).operand(0);
}
if (validator.expand(sqlNode, scope).equalsDeep(call, Litmus.IGNORE)) {
return null;
}
}
}
// Cannot use agg fun in ORDER BY clause if have SELECT DISTINCT.
SqlNode originalExpr = validator.getOriginal(call);
final String exprString = originalExpr.toString();
throw validator.newValidationError(call, RESOURCE.notSelectDistinctExpr(exprString));
}
// BY deptno'
return null;
}
if (call.getKind() == SqlKind.FILTER) {
call.operand(0).accept(this);
return null;
}
// Visit the operand in window function
if (call.getKind() == SqlKind.OVER) {
for (SqlNode operand : call.<SqlCall>operand(0).getOperandList()) {
operand.accept(this);
}
// Check the OVER clause
final SqlNode over = call.operand(1);
if (over instanceof SqlCall) {
over.accept(this);
} else if (over instanceof SqlIdentifier) {
// Check the corresponding SqlWindow in WINDOW clause
final SqlWindow window = scope.lookupWindow(((SqlIdentifier) over).getSimple());
window.getPartitionList().accept(this);
window.getOrderList().accept(this);
}
}
if (isGroupExpr(call)) {
// This call matches an expression in the GROUP BY clause.
return null;
}
final SqlCall groupCall = SqlStdOperatorTable.convertAuxiliaryToGroupCall(call);
if (groupCall != null) {
if (isGroupExpr(groupCall)) {
// TUMBLE(rowtime, INTERVAL '1' HOUR')
return null;
}
throw validator.newValidationError(groupCall, RESOURCE.auxiliaryWithoutMatchingGroupCall(call.getOperator().getName(), groupCall.getOperator().getName()));
}
if (call.isA(SqlKind.QUERY)) {
// references to forbidden columns.
return null;
}
// Switch to new scope.
SqlValidatorScope newScope = scope.getOperandScope(call);
scopes.push(newScope);
// Visit the operands (only expressions).
call.getOperator().acceptCall(this, call, true, ArgHandlerImpl.<Void>instance());
// Restore scope.
scopes.pop();
return null;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project calcite by apache.
the class SqlCreateForeignSchema method execute.
public void execute(CalcitePrepare.Context context) {
final Pair<CalciteSchema, String> pair = SqlDdlNodes.schema(context, true, name);
final SchemaPlus subSchema0 = pair.left.plus().getSubSchema(pair.right);
if (subSchema0 != null) {
if (!getReplace() && !ifNotExists) {
throw SqlUtil.newContextException(name.getParserPosition(), RESOURCE.schemaExists(pair.right));
}
}
final Schema subSchema;
final String libraryName;
if (type != null) {
Preconditions.checkArgument(library == null);
final String typeName = (String) value(this.type);
final JsonSchema.Type type = Util.enumVal(JsonSchema.Type.class, typeName.toUpperCase(Locale.ROOT));
if (type != null) {
switch(type) {
case JDBC:
libraryName = JdbcSchema.Factory.class.getName();
break;
default:
libraryName = null;
}
} else {
libraryName = null;
}
if (libraryName == null) {
throw SqlUtil.newContextException(this.type.getParserPosition(), RESOURCE.schemaInvalidType(typeName, Arrays.toString(JsonSchema.Type.values())));
}
} else {
Preconditions.checkArgument(library != null);
libraryName = (String) value(library);
}
final SchemaFactory schemaFactory = AvaticaUtils.instantiatePlugin(SchemaFactory.class, libraryName);
final Map<String, Object> operandMap = new LinkedHashMap<>();
for (Pair<SqlIdentifier, SqlNode> option : options(optionList)) {
operandMap.put(option.left.getSimple(), value(option.right));
}
subSchema = schemaFactory.create(pair.left.plus(), pair.right, operandMap);
pair.left.add(pair.right, subSchema);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project calcite by apache.
the class SqlAdvisorValidator method registerId.
private void registerId(SqlIdentifier id, SqlValidatorScope scope) {
for (int i = 0; i < id.names.size(); i++) {
final SqlParserPos subPos = id.getComponentParserPosition(i);
SqlIdentifier subId = i == id.names.size() - 1 ? id : new SqlIdentifier(id.names.subList(0, i + 1), subPos);
idPositions.put(subPos.toString(), new IdInfo(scope, subId));
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project flink by apache.
the class RichSqlHiveInsert method unparse.
@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
writer.startList(SqlWriter.FrameTypeEnum.SELECT);
String insertKeyword = "INSERT INTO";
if (isUpsert()) {
insertKeyword = "UPSERT INTO";
} else if (isOverwrite()) {
insertKeyword = "INSERT OVERWRITE";
}
writer.sep(insertKeyword);
final int opLeft = getOperator().getLeftPrec();
final int opRight = getOperator().getRightPrec();
getTargetTable().unparse(writer, opLeft, opRight);
if (getTargetColumnList() != null) {
getTargetColumnList().unparse(writer, opLeft, opRight);
}
writer.newlineAndIndent();
if (allPartKeys != null && allPartKeys.size() > 0) {
writer.keyword("PARTITION");
SqlWriter.Frame frame = writer.startList("(", ")");
for (SqlNode node : allPartKeys) {
writer.sep(",", false);
SqlIdentifier partKey = (SqlIdentifier) node;
SqlProperty spec = partKeyToSpec.get(partKey);
if (spec != null) {
spec.unparse(writer, leftPrec, rightPrec);
} else {
partKey.unparse(writer, leftPrec, rightPrec);
}
}
writer.endList(frame);
writer.newlineAndIndent();
}
getSource().unparse(writer, 0, 0);
}
Aggregations