Search in sources :

Example 6 with TableElement

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

the class ImpalaAstBuilder method visitCreateTableLike.

@Override
public Node visitCreateTableLike(ImpalaSqlParser.CreateTableLikeContext context) {
    if (context.PARQUET() != null) {
        addDiff(DiffType.UNSUPPORTED, context.PARQUET().getText(), "[LIKE PARQUET] is not supported");
        throw unsupportedError(ErrorType.UNSUPPORTED_KEYWORDS, "PARQUET", context.parquet);
    }
    // comment
    Optional<String> comment = Optional.empty();
    if (context.COMMENT() != null) {
        comment = Optional.of(((StringLiteral) visit(context.comment)).getValue());
    }
    // like clause
    List<TableElement> elements = new ArrayList<>();
    LikeClause likeClause = new LikeClause(getQualifiedName(context.likeTableName), Optional.of(LikeClause.PropertiesOption.INCLUDING));
    elements.add(likeClause);
    List<Property> properties = new ArrayList<>();
    // external
    if (context.EXTERNAL() != null) {
        if (context.LOCATION() == null) {
            throw unsupportedError(ErrorType.SYNTAX_ERROR, "External attribute should be used with location", context);
        }
        Identifier name = new Identifier("external");
        Expression value = new Identifier("true");
        properties.add(new Property(name, value));
        addDiff(DiffType.MODIFIED, context.EXTERNAL().getText(), "external = true", "[external] is formatted");
    }
    // location
    if (context.LOCATION() != null) {
        Identifier name = new Identifier("location");
        Expression value = (StringLiteral) visit(context.location);
        properties.add(new Property(name, value));
        addDiff(DiffType.MODIFIED, context.LOCATION().getText(), LOCATION + " = " + value, "[location] is formatted");
    }
    // stored as
    if (context.STORED_AS() != null) {
        String storedAsString = ((Identifier) visit(context.stored_as)).getValue();
        Expression value = new StringLiteral(getFileFormat(storedAsString));
        properties.add(new Property(new Identifier(FORMAT), value));
        addDiff(DiffType.MODIFIED, context.STORED_AS().getText(), FORMAT, "[stored as] is formatted");
    }
    return new CreateTable(getLocation(context), getQualifiedName(context.tblName), elements, context.EXISTS() != null, properties, comment);
}
Also used : LikeClause(io.prestosql.sql.tree.LikeClause) Identifier(io.prestosql.sql.tree.Identifier) StringLiteral(io.prestosql.sql.tree.StringLiteral) ArithmeticUnaryExpression(io.prestosql.sql.tree.ArithmeticUnaryExpression) LambdaExpression(io.prestosql.sql.tree.LambdaExpression) LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) SimpleCaseExpression(io.prestosql.sql.tree.SimpleCaseExpression) SubqueryExpression(io.prestosql.sql.tree.SubqueryExpression) IfExpression(io.prestosql.sql.tree.IfExpression) InListExpression(io.prestosql.sql.tree.InListExpression) CoalesceExpression(io.prestosql.sql.tree.CoalesceExpression) ArithmeticBinaryExpression(io.prestosql.sql.tree.ArithmeticBinaryExpression) SearchedCaseExpression(io.prestosql.sql.tree.SearchedCaseExpression) SubscriptExpression(io.prestosql.sql.tree.SubscriptExpression) DereferenceExpression(io.prestosql.sql.tree.DereferenceExpression) QuantifiedComparisonExpression(io.prestosql.sql.tree.QuantifiedComparisonExpression) NullIfExpression(io.prestosql.sql.tree.NullIfExpression) ArrayList(java.util.ArrayList) CreateTable(io.prestosql.sql.tree.CreateTable) Property(io.prestosql.sql.tree.Property) TableElement(io.prestosql.sql.tree.TableElement)

Example 7 with TableElement

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

the class TestCreateTableTask method testCreateWithNotNullColumns.

@Test
public void testCreateWithNotNullColumns() {
    metadata.setConnectorCapabilities(NOT_NULL_COLUMN_CONSTRAINT);
    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()));
    assertEquals(metadata.getCreateTableCallCount(), 1);
    List<ColumnMetadata> columns = metadata.getReceivedTableMetadata().get(0).getColumns();
    assertEquals(columns.size(), 3);
    assertEquals(columns.get(0).getName(), "a");
    assertEquals(columns.get(0).getType().getDisplayName().toUpperCase(ENGLISH), "DATE");
    assertTrue(columns.get(0).isNullable());
    assertEquals(columns.get(1).getName(), "b");
    assertEquals(columns.get(1).getType().getDisplayName().toUpperCase(ENGLISH), "VARCHAR");
    assertFalse(columns.get(1).isNullable());
    assertEquals(columns.get(2).getName(), "c");
    assertEquals(columns.get(2).getType().getDisplayName().toUpperCase(ENGLISH), "VARBINARY");
    assertFalse(columns.get(2).isNullable());
}
Also used : ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) 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

CreateTable (io.prestosql.sql.tree.CreateTable)7 TableElement (io.prestosql.sql.tree.TableElement)7 ColumnDefinition (io.prestosql.sql.tree.ColumnDefinition)5 Expression (io.prestosql.sql.tree.Expression)5 ArithmeticBinaryExpression (io.prestosql.sql.tree.ArithmeticBinaryExpression)4 ArithmeticUnaryExpression (io.prestosql.sql.tree.ArithmeticUnaryExpression)4 CoalesceExpression (io.prestosql.sql.tree.CoalesceExpression)4 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)4 DereferenceExpression (io.prestosql.sql.tree.DereferenceExpression)4 Identifier (io.prestosql.sql.tree.Identifier)4 IfExpression (io.prestosql.sql.tree.IfExpression)4 InListExpression (io.prestosql.sql.tree.InListExpression)4 LogicalBinaryExpression (io.prestosql.sql.tree.LogicalBinaryExpression)4 NotExpression (io.prestosql.sql.tree.NotExpression)4 NullIfExpression (io.prestosql.sql.tree.NullIfExpression)4 Property (io.prestosql.sql.tree.Property)4 QuantifiedComparisonExpression (io.prestosql.sql.tree.QuantifiedComparisonExpression)4 SearchedCaseExpression (io.prestosql.sql.tree.SearchedCaseExpression)4 SimpleCaseExpression (io.prestosql.sql.tree.SimpleCaseExpression)4 StringLiteral (io.prestosql.sql.tree.StringLiteral)4