use of io.prestosql.sql.tree.CreateSchema in project hetu-core by openlookeng.
the class TestSqlParser method testCreateSchema.
@Test
public void testCreateSchema() {
assertStatement("CREATE SCHEMA test", new CreateSchema(QualifiedName.of("test"), false, ImmutableList.of()));
assertStatement("CREATE SCHEMA IF NOT EXISTS test", new CreateSchema(QualifiedName.of("test"), true, ImmutableList.of()));
assertStatement("CREATE SCHEMA test WITH (a = 'apple', b = 123)", new CreateSchema(QualifiedName.of("test"), false, ImmutableList.of(new Property(new Identifier("a"), new StringLiteral("apple")), new Property(new Identifier("b"), new LongLiteral("123")))));
assertStatement("CREATE SCHEMA \"some name that contains space\"", new CreateSchema(QualifiedName.of("some name that contains space"), false, ImmutableList.of()));
}
use of io.prestosql.sql.tree.CreateSchema in project hetu-core by openlookeng.
the class ImpalaAstBuilder method visitCreateSchema.
@Override
public Node visitCreateSchema(ImpalaSqlParser.CreateSchemaContext context) {
List<Property> properties = new ArrayList<>();
if (context.COMMENT() != null) {
// Comment is not supported yet, give an warning message.
String comment = ((StringLiteral) visit(context.comment)).getValue();
addDiff(DiffType.DELETED, context.COMMENT().getText(), null, null);
addDiff(DiffType.DELETED, comment, null, format("[COMMENT] is omitted: %s", comment));
}
// handle location by properties
if (context.LOCATION() != null) {
Identifier identifier = new Identifier("location");
StringLiteral location = (StringLiteral) visit(context.location);
properties.add(new Property(getLocation(context), identifier, location));
addDiff(DiffType.INSERTED, null, "WITH", "New [with] clause");
addDiff(DiffType.MODIFIED, location.toString(), "location = " + location.toString(), "[location] is formatted");
}
// if database keyword to schema keyword
if (context.DATABASE() != null && !context.DATABASE().getText().equalsIgnoreCase("schema")) {
addDiff(DiffType.MODIFIED, context.DATABASE().getText(), "SCHEMA", "[DATABASE] is updated to [SCHEMA]");
}
return new CreateSchema(getLocation(context), getQualifiedName(context.qualifiedName()), context.EXISTS() != null, properties);
}
use of io.prestosql.sql.tree.CreateSchema in project hetu-core by openlookeng.
the class HiveAstBuilder method visitCreateSchema.
@Override
public Node visitCreateSchema(HiveSqlParser.CreateSchemaContext context) {
if (context.DBPROPERTIES() != null) {
addDiff(DiffType.UNSUPPORTED, context.DBPROPERTIES().getText(), "[WITH DBPROPERTIES] is not supported");
throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported attribute: DBPROPERTIES", context.properties());
}
List<Property> properties = new ArrayList<>();
if (context.COMMENT() != null) {
String comment = ((StringLiteral) visit(context.comment)).getValue();
addDiff(DiffType.DELETED, context.COMMENT().getText(), null, null);
addDiff(DiffType.DELETED, comment, null, format("[COMMENT] is omitted: %s", comment));
}
if (context.LOCATION() != null) {
Identifier identifier = new Identifier("location");
StringLiteral location = (StringLiteral) visit(context.location);
properties.add(new Property(getLocation(context), identifier, location));
addDiff(DiffType.INSERTED, null, "WITH", "New [with] clause");
addDiff(DiffType.MODIFIED, location.toString(), "location = " + location.toString(), "[location] is formatted");
}
// if database keyword to schema keyword
if (context.DATABASE() != null && !context.DATABASE().getText().equalsIgnoreCase("schema")) {
addDiff(DiffType.MODIFIED, context.DATABASE().getText(), "SCHEMA", "[DATABASE] is updated to [SCHEMA]");
}
return new CreateSchema(getLocation(context), getQualifiedName(context.qualifiedName()), context.EXISTS() != null, properties);
}
Aggregations