use of org.apache.beam.sdk.extensions.sql.impl.BeamCalciteSchema in project beam by apache.
the class SqlDropObject method execute.
@Override
public void execute(CalcitePrepare.Context context) {
final List<String> path = context.getDefaultSchemaPath();
CalciteSchema schema = context.getRootSchema();
for (String p : path) {
schema = schema.getSubSchema(p, true);
if (schema == null) {
throw new AssertionError(String.format("Got null sub-schema for path '%s' in %s", p, path));
}
}
final boolean existed;
switch(getKind()) {
case DROP_TABLE:
if (schema.schema instanceof BeamCalciteSchema) {
BeamCalciteSchema beamSchema = (BeamCalciteSchema) schema.schema;
beamSchema.getTableProvider().dropTable(name.getSimple());
existed = true;
} else {
existed = schema.removeTable(name.getSimple());
}
if (!existed && !ifExists) {
throw SqlUtil.newContextException(name.getParserPosition(), RESOURCE.tableNotFound(name.getSimple()));
}
break;
default:
throw new AssertionError(getKind());
}
}
use of org.apache.beam.sdk.extensions.sql.impl.BeamCalciteSchema in project beam by apache.
the class SqlSetOptionBeam method execute.
@Override
public void execute(CalcitePrepare.Context context) {
final SqlIdentifier name = getName();
final SqlNode value = getValue();
final Pair<CalciteSchema, String> pair = SqlDdlNodes.schema(context, true, name);
if (!(pair.left.schema instanceof BeamCalciteSchema)) {
throw SqlUtil.newContextException(name.getParserPosition(), RESOURCE.internal("Schema is not instanceof BeamCalciteSchema"));
}
BeamCalciteSchema schema = (BeamCalciteSchema) pair.left.schema;
if (value != null) {
schema.setPipelineOption(pair.right, SqlDdlNodes.getString(value));
} else if ("ALL".equals(pair.right)) {
schema.removeAllPipelineOptions();
} else {
schema.removePipelineOption(pair.right);
}
}
use of org.apache.beam.sdk.extensions.sql.impl.BeamCalciteSchema in project beam by apache.
the class SqlCreateExternalTable method execute.
@Override
public void execute(CalcitePrepare.Context context) {
final Pair<CalciteSchema, String> pair = SqlDdlNodes.schema(context, true, name);
if (pair.left.plus().getTable(pair.right) != null) {
// Table exists.
if (!ifNotExists) {
// They did not specify IF NOT EXISTS, so give error.
throw SqlUtil.newContextException(name.getParserPosition(), RESOURCE.tableExists(pair.right));
}
return;
}
// Table does not exist. Create it.
if (!(pair.left.schema instanceof BeamCalciteSchema)) {
throw SqlUtil.newContextException(name.getParserPosition(), RESOURCE.internal("Schema is not instanceof BeamCalciteSchema"));
}
BeamCalciteSchema schema = (BeamCalciteSchema) pair.left.schema;
schema.getTableProvider().createTable(toTable());
}
Aggregations