Search in sources :

Example 1 with AddColumn

use of io.prestosql.sql.tree.AddColumn 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 2 with AddColumn

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

the class HiveAstBuilder method visitAddReplaceColumn.

@Override
public Node visitAddReplaceColumn(HiveSqlParser.AddReplaceColumnContext context) {
    if (context.CASCADE() != null) {
        addDiff(DiffType.UNSUPPORTED, context.CASCADE().getText(), "[CASCADE] is not supported");
        throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported statement: CASCADE", context);
    }
    if (context.REPLACE() != null) {
        addDiff(DiffType.UNSUPPORTED, context.REPLACE().getText(), "[REPLACE] is not supported");
        throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported statement: REPLACE", context);
    }
    if (context.PARTITION() != null) {
        addDiff(DiffType.UNSUPPORTED, context.PARTITION().getText(), "[PARTITION] is not supported");
        throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported statement: PARTITION", context.partition);
    }
    if (context.tableElement().size() > 1) {
        addDiff(DiffType.UNSUPPORTED, context.ADD().getText(), "[ADD MULTIPLE COLUMNS] is not supported");
        addDiff(DiffType.UNSUPPORTED, context.COLUMNS().getText(), null);
        throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported add multiple columns", context.tableElement(0));
    }
    HiveSqlParser.ColumnDefinitionContext columnDefinitionContext = context.tableElement(0).columnDefinition();
    Identifier identifier = (Identifier) visit(columnDefinitionContext.identifier());
    String type = getType(columnDefinitionContext.type());
    Optional<String> comment = Optional.empty();
    if (columnDefinitionContext.COMMENT() != null) {
        comment = Optional.of(((StringLiteral) visit(columnDefinitionContext.string())).getValue());
    }
    ColumnDefinition columnDefinition = new ColumnDefinition(identifier, type, true, ImmutableList.of(), comment);
    return new AddColumn(getLocation(context), getQualifiedName(context.qualifiedName()), columnDefinition);
}
Also used : Identifier(io.prestosql.sql.tree.Identifier) StringLiteral(io.prestosql.sql.tree.StringLiteral) HiveSqlParser(io.hetu.core.migration.source.hive.HiveSqlParser) ColumnDefinition(io.prestosql.sql.tree.ColumnDefinition) AddColumn(io.prestosql.sql.tree.AddColumn)

Example 3 with AddColumn

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

the class ImpalaAstBuilder method visitAddSingleColumn.

@Override
public Node visitAddSingleColumn(ImpalaSqlParser.AddSingleColumnContext context) {
    if (context.EXISTS() != null) {
        addDiff(DiffType.UNSUPPORTED, context.EXISTS().getText(), "[IF NOT EXISTS] is not supported");
        throw unsupportedError(ErrorType.UNSUPPORTED_KEYWORDS, "[IF NOT EXISTS] is not supported", context);
    }
    if (context.columnSpecWithKudu().kuduAttributes() != null) {
        addDiff(DiffType.UNSUPPORTED, context.columnSpecWithKudu().kuduAttributes().getText(), "[KUDU Attribute] is not supported");
        throw unsupportedError(ErrorType.UNSUPPORTED_KEYWORDS, "[KUDU Attribute] is not supported", context);
    }
    Optional<String> comment = Optional.empty();
    if (context.columnSpecWithKudu().COMMENT() != null) {
        comment = Optional.of(((StringLiteral) visit(context.columnSpecWithKudu().string())).getValue());
    }
    ColumnDefinition columnDefinition = new ColumnDefinition((Identifier) visit(context.columnSpecWithKudu().identifier()), getType(context.columnSpecWithKudu().type()), true, new ArrayList<>(), comment);
    return new AddColumn(getLocation(context), getQualifiedName(context.qualifiedName()), columnDefinition);
}
Also used : StringLiteral(io.prestosql.sql.tree.StringLiteral) ColumnDefinition(io.prestosql.sql.tree.ColumnDefinition) AddColumn(io.prestosql.sql.tree.AddColumn)

Example 4 with AddColumn

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

the class ImpalaAstBuilder method visitAddColumns.

@Override
public Node visitAddColumns(ImpalaSqlParser.AddColumnsContext context) {
    if (context.EXISTS() != null) {
        addDiff(DiffType.UNSUPPORTED, context.EXISTS().getText(), "[IF NOT EXISTS] is not supported");
        throw unsupportedError(ErrorType.UNSUPPORTED_KEYWORDS, "[IF NOT EXISTS] is not supported", context);
    }
    if (context.columnSpecWithKudu().size() > 1) {
        // does not support add multiple column
        addDiff(DiffType.UNSUPPORTED, context.columnSpecWithKudu(1).getText(), "adding [Multiple columns] is not supported");
        throw unsupportedError(ErrorType.UNSUPPORTED_KEYWORDS, "adding [Multiple columns] is not supported", context);
    }
    if (context.columnSpecWithKudu(0).kuduAttributes() != null) {
        addDiff(DiffType.UNSUPPORTED, context.columnSpecWithKudu(0).kuduAttributes().getText(), "[KUDU Attribute] is not supported");
        throw unsupportedError(ErrorType.UNSUPPORTED_KEYWORDS, "[KUDU Attribute] is not supported", context);
    }
    Optional<String> comment = Optional.empty();
    if (context.columnSpecWithKudu(0).COMMENT() != null) {
        comment = Optional.of(((StringLiteral) visit(context.columnSpecWithKudu(0).string())).getValue());
    }
    addDiff(DiffType.MODIFIED, context.COLUMNS().getText(), "COLUMN", "[COLUMNS] is modified to column");
    ColumnDefinition columnDefinition = new ColumnDefinition((Identifier) visit(context.columnSpecWithKudu(0).identifier()), getType(context.columnSpecWithKudu(0).type()), true, new ArrayList<>(), comment);
    return new AddColumn(getLocation(context), getQualifiedName(context.qualifiedName()), columnDefinition);
}
Also used : StringLiteral(io.prestosql.sql.tree.StringLiteral) ColumnDefinition(io.prestosql.sql.tree.ColumnDefinition) AddColumn(io.prestosql.sql.tree.AddColumn)

Aggregations

AddColumn (io.prestosql.sql.tree.AddColumn)4 ColumnDefinition (io.prestosql.sql.tree.ColumnDefinition)4 StringLiteral (io.prestosql.sql.tree.StringLiteral)3 HiveSqlParser (io.hetu.core.migration.source.hive.HiveSqlParser)1 Identifier (io.prestosql.sql.tree.Identifier)1 Test (org.testng.annotations.Test)1