Search in sources :

Example 1 with ColumnDefinition

use of io.prestosql.sql.tree.ColumnDefinition in project hetu-core by openlookeng.

the class TestSqlParser method testCreateTable.

@Test
public void testCreateTable() {
    assertStatement("CREATE TABLE foo (a VARCHAR, b BIGINT COMMENT 'hello world', c IPADDRESS)", new CreateTable(QualifiedName.of("foo"), ImmutableList.of(new ColumnDefinition(identifier("a"), "VARCHAR", true, emptyList(), Optional.empty()), new ColumnDefinition(identifier("b"), "BIGINT", true, emptyList(), Optional.of("hello world")), new ColumnDefinition(identifier("c"), "IPADDRESS", true, emptyList(), Optional.empty())), false, ImmutableList.of(), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS bar (c TIMESTAMP)", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new ColumnDefinition(identifier("c"), "TIMESTAMP", true, emptyList(), Optional.empty())), true, ImmutableList.of(), Optional.empty()));
    // with properties
    assertStatement("CREATE TABLE IF NOT EXISTS bar (c TIMESTAMP WITH (nullable = true, compression = 'LZ4'))", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new ColumnDefinition(identifier("c"), "TIMESTAMP", true, ImmutableList.of(new Property(new Identifier("nullable"), BooleanLiteral.TRUE_LITERAL), new Property(new Identifier("compression"), new StringLiteral("LZ4"))), Optional.empty())), true, ImmutableList.of(), Optional.empty()));
    // with LIKE
    assertStatement("CREATE TABLE IF NOT EXISTS bar (LIKE like_table)", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new LikeClause(QualifiedName.of("like_table"), Optional.empty())), true, ImmutableList.of(), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS bar (c TIMESTAMP, LIKE like_table)", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new ColumnDefinition(identifier("c"), "TIMESTAMP", true, emptyList(), Optional.empty()), new LikeClause(QualifiedName.of("like_table"), Optional.empty())), true, ImmutableList.of(), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS bar (c TIMESTAMP, LIKE like_table, d DATE)", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new ColumnDefinition(identifier("c"), "TIMESTAMP", true, emptyList(), Optional.empty()), new LikeClause(QualifiedName.of("like_table"), Optional.empty()), new ColumnDefinition(identifier("d"), "DATE", true, emptyList(), Optional.empty())), true, ImmutableList.of(), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS bar (LIKE like_table INCLUDING PROPERTIES)", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new LikeClause(QualifiedName.of("like_table"), Optional.of(LikeClause.PropertiesOption.INCLUDING))), true, ImmutableList.of(), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS bar (c TIMESTAMP, LIKE like_table EXCLUDING PROPERTIES)", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new ColumnDefinition(identifier("c"), "TIMESTAMP", true, emptyList(), Optional.empty()), new LikeClause(QualifiedName.of("like_table"), Optional.of(LikeClause.PropertiesOption.EXCLUDING))), true, ImmutableList.of(), Optional.empty()));
    assertStatement("CREATE TABLE IF NOT EXISTS bar (c TIMESTAMP, LIKE like_table EXCLUDING PROPERTIES) COMMENT 'test'", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new ColumnDefinition(identifier("c"), "TIMESTAMP", true, emptyList(), Optional.empty()), new LikeClause(QualifiedName.of("like_table"), Optional.of(LikeClause.PropertiesOption.EXCLUDING))), true, ImmutableList.of(), Optional.of("test")));
}
Also used : LikeClause(io.prestosql.sql.tree.LikeClause) Identifier(io.prestosql.sql.tree.Identifier) QueryUtil.quotedIdentifier(io.prestosql.sql.QueryUtil.quotedIdentifier) StringLiteral(io.prestosql.sql.tree.StringLiteral) CreateTable(io.prestosql.sql.tree.CreateTable) Property(io.prestosql.sql.tree.Property) ColumnDefinition(io.prestosql.sql.tree.ColumnDefinition) Test(org.testng.annotations.Test)

Example 2 with ColumnDefinition

use of io.prestosql.sql.tree.ColumnDefinition in project hetu-core by openlookeng.

the class TestSqlParser method testAddColumn.

@Test
public void testAddColumn() {
    assertStatement("ALTER TABLE foo.t ADD COLUMN c bigint", new AddColumn(QualifiedName.of("foo", "t"), new ColumnDefinition(identifier("c"), "bigint", true, emptyList(), Optional.empty())));
    assertStatement("ALTER TABLE foo.t ADD COLUMN d double NOT NULL", new AddColumn(QualifiedName.of("foo", "t"), new ColumnDefinition(identifier("d"), "double", false, emptyList(), Optional.empty())));
}
Also used : AddColumn(io.prestosql.sql.tree.AddColumn) ColumnDefinition(io.prestosql.sql.tree.ColumnDefinition) Test(org.testng.annotations.Test)

Example 3 with ColumnDefinition

use of io.prestosql.sql.tree.ColumnDefinition in project hetu-core by openlookeng.

the class TestCreateTableTask method testCreateTableNotExistsTrue.

@Test
public void testCreateTableNotExistsTrue() {
    CreateTable statement = new CreateTable(QualifiedName.of("test_table"), ImmutableList.of(new ColumnDefinition(identifier("a"), "BIGINT", true, emptyList(), Optional.empty())), true, ImmutableList.of(), Optional.empty());
    getFutureValue(new CreateTableTask().internalExecute(statement, metadata, new AllowAllAccessControl(), testSession, emptyList()));
    assertEquals(metadata.getCreateTableCallCount(), 1);
}
Also used : AllowAllAccessControl(io.prestosql.security.AllowAllAccessControl) CreateTable(io.prestosql.sql.tree.CreateTable) ColumnDefinition(io.prestosql.sql.tree.ColumnDefinition) Test(org.testng.annotations.Test)

Example 4 with ColumnDefinition

use of io.prestosql.sql.tree.ColumnDefinition in project hetu-core by openlookeng.

the class TestCreateTableTask method testCreateTableNotExistsFalse.

@Test
public void testCreateTableNotExistsFalse() {
    CreateTable statement = new CreateTable(QualifiedName.of("test_table"), ImmutableList.of(new ColumnDefinition(identifier("a"), "BIGINT", true, emptyList(), Optional.empty())), false, ImmutableList.of(), Optional.empty());
    try {
        getFutureValue(new CreateTableTask().internalExecute(statement, metadata, new AllowAllAccessControl(), testSession, emptyList()));
        fail("expected exception");
    } catch (RuntimeException e) {
        // Expected
        assertTrue(e instanceof PrestoException);
        PrestoException prestoException = (PrestoException) e;
        assertEquals(prestoException.getErrorCode(), ALREADY_EXISTS.toErrorCode());
    }
    assertEquals(metadata.getCreateTableCallCount(), 1);
}
Also used : AllowAllAccessControl(io.prestosql.security.AllowAllAccessControl) CreateTable(io.prestosql.sql.tree.CreateTable) PrestoException(io.prestosql.spi.PrestoException) ColumnDefinition(io.prestosql.sql.tree.ColumnDefinition) Test(org.testng.annotations.Test)

Example 5 with ColumnDefinition

use of io.prestosql.sql.tree.ColumnDefinition in project hetu-core by openlookeng.

the class TestCreateTableTask method testCreateWithUnsupportedConnectorThrowsWhenNotNull.

@Test(expectedExceptions = SemanticException.class, expectedExceptionsMessageRegExp = ".*does not support non-null column for column name 'b'")
public void testCreateWithUnsupportedConnectorThrowsWhenNotNull() {
    List<TableElement> inputColumns = ImmutableList.of(new ColumnDefinition(identifier("a"), "DATE", true, emptyList(), Optional.empty()), new ColumnDefinition(identifier("b"), "VARCHAR", false, emptyList(), Optional.empty()), new ColumnDefinition(identifier("c"), "VARBINARY", false, emptyList(), Optional.empty()));
    CreateTable statement = new CreateTable(QualifiedName.of("test_table"), inputColumns, true, ImmutableList.of(), Optional.empty());
    getFutureValue(new CreateTableTask().internalExecute(statement, metadata, new AllowAllAccessControl(), testSession, emptyList()));
}
Also used : AllowAllAccessControl(io.prestosql.security.AllowAllAccessControl) CreateTable(io.prestosql.sql.tree.CreateTable) TableElement(io.prestosql.sql.tree.TableElement) ColumnDefinition(io.prestosql.sql.tree.ColumnDefinition) Test(org.testng.annotations.Test)

Aggregations

ColumnDefinition (io.prestosql.sql.tree.ColumnDefinition)13 CreateTable (io.prestosql.sql.tree.CreateTable)8 StringLiteral (io.prestosql.sql.tree.StringLiteral)6 Test (org.testng.annotations.Test)6 TableElement (io.prestosql.sql.tree.TableElement)5 AllowAllAccessControl (io.prestosql.security.AllowAllAccessControl)4 AddColumn (io.prestosql.sql.tree.AddColumn)4 Expression (io.prestosql.sql.tree.Expression)4 Identifier (io.prestosql.sql.tree.Identifier)4 PrestoException (io.prestosql.spi.PrestoException)3 ColumnMetadata (io.prestosql.spi.connector.ColumnMetadata)3 Property (io.prestosql.sql.tree.Property)3 HiveSqlParser (io.hetu.core.migration.source.hive.HiveSqlParser)2 Session (io.prestosql.Session)2 MetadataUtil.createQualifiedObjectName (io.prestosql.metadata.MetadataUtil.createQualifiedObjectName)2 CatalogName (io.prestosql.spi.connector.CatalogName)2 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)2 TableHandle (io.prestosql.spi.metadata.TableHandle)2 Type (io.prestosql.spi.type.Type)2 TypeNotFoundException (io.prestosql.spi.type.TypeNotFoundException)2