Search in sources :

Example 1 with CreateSchema

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()));
}
Also used : Identifier(io.prestosql.sql.tree.Identifier) QueryUtil.quotedIdentifier(io.prestosql.sql.QueryUtil.quotedIdentifier) StringLiteral(io.prestosql.sql.tree.StringLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) CreateSchema(io.prestosql.sql.tree.CreateSchema) Property(io.prestosql.sql.tree.Property) Test(org.testng.annotations.Test)

Example 2 with CreateSchema

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);
}
Also used : Identifier(io.prestosql.sql.tree.Identifier) StringLiteral(io.prestosql.sql.tree.StringLiteral) ArrayList(java.util.ArrayList) CreateSchema(io.prestosql.sql.tree.CreateSchema) Property(io.prestosql.sql.tree.Property)

Example 3 with CreateSchema

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);
}
Also used : Identifier(io.prestosql.sql.tree.Identifier) StringLiteral(io.prestosql.sql.tree.StringLiteral) ArrayList(java.util.ArrayList) CreateSchema(io.prestosql.sql.tree.CreateSchema) Property(io.prestosql.sql.tree.Property)

Aggregations

CreateSchema (io.prestosql.sql.tree.CreateSchema)3 Identifier (io.prestosql.sql.tree.Identifier)3 Property (io.prestosql.sql.tree.Property)3 StringLiteral (io.prestosql.sql.tree.StringLiteral)3 ArrayList (java.util.ArrayList)2 QueryUtil.quotedIdentifier (io.prestosql.sql.QueryUtil.quotedIdentifier)1 LongLiteral (io.prestosql.sql.tree.LongLiteral)1 Test (org.testng.annotations.Test)1