Search in sources :

Example 21 with StringLiteral

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

the class HiveAstBuilder method visitCreateTableAsSelect.

@Override
public Node visitCreateTableAsSelect(HiveSqlParser.CreateTableAsSelectContext context) {
    if (context.TEMPORARY() != null) {
        addDiff(DiffType.UNSUPPORTED, context.TEMPORARY().getText(), "[TEMPORARY] is not supported");
        throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported statement: CREATE TEMPORARY TABLE", context);
    }
    Optional<String> comment = Optional.empty();
    if (context.COMMENT() != null) {
        comment = Optional.of(((StringLiteral) visit(context.string(0))).getValue());
    }
    Optional<List<Identifier>> columnAliases = Optional.empty();
    if (context.columnAliases() != null) {
        columnAliases = Optional.of(visit(context.columnAliases().identifier(), Identifier.class));
    }
    List<Property> properties = new ArrayList<>();
    if (context.TRANSACTIONAL() != null) {
        Identifier name = new Identifier("transactional");
        Expression value = new Identifier("true");
        properties.add(new Property(name, value));
        addDiff(DiffType.MODIFIED, context.TRANSACTIONAL().getText(), "transactional = true", "[TRANSACTIONAL] is formatted");
    }
    if (context.STORED_AS() != null) {
        Identifier name = new Identifier("format");
        String storedAsString = ((Identifier) visit(context.stored_as)).getValue();
        Expression value = new StringLiteral(getFileFormat(storedAsString));
        properties.add(new Property(name, value));
        addDiff(DiffType.MODIFIED, context.STORED_AS().getText(), FORMAT, "[STORED AS] is formatted");
    }
    if (context.LOCATION() != null) {
        Identifier name = new Identifier("location");
        Expression value = (StringLiteral) visit(context.location);
        properties.add(new Property(name, value));
    }
    if (context.TBLPROPERTIES() != null) {
        List<Property> tableProperties = visit(context.properties().property(), Property.class);
        for (int i = 0; i < tableProperties.size(); i++) {
            Property property = tableProperties.get(i);
            if (property.getName().getValue().equalsIgnoreCase("transactional")) {
                Identifier name = new Identifier("transactional");
                Expression value = new Identifier(unquote(property.getValue().toString()));
                properties.add(new Property(name, value));
                addDiff(DiffType.MODIFIED, property.getName().getValue(), "transactional = ", "[TRANSACTIONAL] is formatted");
            } else {
                addDiff(DiffType.UNSUPPORTED, property.getName().getValue(), "[TBLPROPERTIES] has unsupported properties");
                throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, format("Unsupported attribute: %s", property.getName().getValue()), context.properties());
            }
        }
    }
    return new CreateTableAsSelect(getLocation(context), getQualifiedName(context.qualifiedName()), (Query) visit(context.query()), context.EXISTS() != null, properties, true, columnAliases, comment);
}
Also used : Identifier(io.prestosql.sql.tree.Identifier) StringLiteral(io.prestosql.sql.tree.StringLiteral) ArithmeticUnaryExpression(io.prestosql.sql.tree.ArithmeticUnaryExpression) 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) CreateTableAsSelect(io.prestosql.sql.tree.CreateTableAsSelect) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) Property(io.prestosql.sql.tree.Property)

Example 22 with StringLiteral

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

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

the class HiveAstBuilder method visitCreateTableLike.

@Override
public Node visitCreateTableLike(HiveSqlParser.CreateTableLikeContext context) {
    List<TableElement> elements = new ArrayList<>();
    LikeClause likeClause = new LikeClause(getQualifiedName(context.likeTableName), Optional.of(LikeClause.PropertiesOption.EXCLUDING));
    elements.add(likeClause);
    addDiff(DiffType.INSERTED, null, "EXCLUDING PROPERTIES", "add keyword [EXCLUDING PROPERTIES]");
    List<Property> properties = new ArrayList<>();
    if (context.EXTERNAL() != null) {
        if (context.LOCATION() == null) {
            addDiff(DiffType.UNSUPPORTED, context.EXTERNAL().getText(), "[EXTERNAL] should be used with location");
            throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "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");
    }
    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");
    }
    return new CreateTable(getLocation(context), getQualifiedName(context.tableName), elements, context.EXISTS() != null, properties, Optional.empty());
}
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) 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 24 with StringLiteral

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

the class HiveAstBuilder method visitCreateTable.

@Override
public Node visitCreateTable(HiveSqlParser.CreateTableContext context) {
    if (context.TEMPORARY() != null) {
        addDiff(DiffType.UNSUPPORTED, context.TEMPORARY().getText(), "[TEMPORARY] is not supported");
        throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported statement: CREATE TEMPORARY TABLE", context);
    }
    if (context.constraintSpecification() != null) {
        HiveSqlParser.ConstraintSpecificationContext constraintContext = context.constraintSpecification();
        if (constraintContext.PRIMARY() != null) {
            addDiff(DiffType.UNSUPPORTED, constraintContext.PRIMARY().getText(), "[PRIMARY KEY] is not supported");
            addDiff(DiffType.UNSUPPORTED, constraintContext.KEY().getText(), null);
        }
        if (constraintContext.CONSTRAINT() != null) {
            addDiff(DiffType.UNSUPPORTED, constraintContext.CONSTRAINT().getText(), "[CONSTRAINT] is not supported");
        }
        throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported constraint statement", context.constraintSpecification());
    }
    Optional<String> comment = Optional.empty();
    if (context.COMMENT() != null) {
        comment = Optional.of(((StringLiteral) visit(context.string(0))).getValue());
    }
    List<Property> properties = new ArrayList<>();
    if (context.TRANSACTIONAL() != null) {
        Identifier name = new Identifier("transactional");
        Expression value = new Identifier("true");
        properties.add(new Property(name, value));
        addDiff(DiffType.MODIFIED, context.TRANSACTIONAL().getText(), "transactional = true", "[TRANSACTIONAL] is formatted");
    }
    List<TableElement> elements = getTableElements(context.tableElement());
    if (context.PARTITIONED() != null) {
        Identifier name = new Identifier("partitioned_by");
        List<ColumnDefinition> columnDefinitions = getColumnDefinitions(context.partitionedBy().columnDefinition());
        List<Expression> expressions = new ArrayList<>();
        Iterator<ColumnDefinition> iterator = columnDefinitions.iterator();
        while (iterator.hasNext()) {
            ColumnDefinition iter = iterator.next();
            expressions.add(new StringLiteral(iter.getName().getValue()));
            elements.add(new ColumnDefinition(iter.getName(), iter.getType(), true, emptyList(), Optional.empty()));
        }
        Expression value = new ArrayConstructor(expressions);
        properties.add(new Property(name, value));
        addDiff(DiffType.MODIFIED, context.PARTITIONED().getText(), PARTITIONED_BY, "[PARTITIONED BY] is formatted");
    }
    if (context.CLUSTERED() != null) {
        Identifier name = new Identifier("bucketed_by");
        List<Expression> quotedExpressions = new ArrayList<>();
        List<Expression> expressions = getExpressions(context.clusteredBy().expression());
        for (int i = 0; i < expressions.size(); i++) {
            quotedExpressions.add(new StringLiteral(expressions.get(i).toString()));
        }
        Expression value = new ArrayConstructor(quotedExpressions);
        properties.add(new Property(name, value));
        addDiff(DiffType.MODIFIED, context.CLUSTERED().getText(), "bucketed_by", "[CLUSTERED BY] is formatted");
    }
    if (context.SORTED() != null) {
        Identifier name = new Identifier("sorted_by");
        List<Expression> expressions = new ArrayList<>();
        List<HiveSqlParser.SortItemContext> sortItemContexts = context.sortedBy().sortItem();
        for (int i = 0; i < sortItemContexts.size(); i++) {
            HiveSqlParser.SortItemContext sortItemContext = sortItemContexts.get(i);
            String sortedBy = sortItemContext.expression().getText();
            if (sortItemContext.ordering != null) {
                sortedBy += " " + sortItemContext.ordering.getText();
            }
            expressions.add(new StringLiteral(sortedBy));
        }
        Expression value = new ArrayConstructor(expressions);
        properties.add(new Property(name, value));
        addDiff(DiffType.MODIFIED, context.SORTED().getText(), SORTED_BY, "[SORTED BY] is formatted");
    }
    if (context.INTO() != null) {
        Identifier name = new Identifier("bucket_count");
        Expression value = (Expression) visit(context.bucketcount);
        properties.add(new Property(name, value));
        addDiff(DiffType.MODIFIED, context.INTO().getText(), "bucket_count", "[INTO BUCKETS] is formatted");
    }
    if (context.SKEWED() != null) {
        addDiff(DiffType.UNSUPPORTED, context.SKEWED().getText(), "[SKEWED] is not supported");
        throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported statement: SKEWED", context.columnAliases());
    }
    if (context.ROW() != null) {
        addDiff(DiffType.UNSUPPORTED, context.ROW().getText(), "[ROW FORMAT] is not supported");
        throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported statement: ROW FORMAT", context.rowFormat());
    }
    if (context.STORED() != null) {
        addDiff(DiffType.UNSUPPORTED, context.STORED().getText(), "[STORED BY] is not supported");
        throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported statement: STORED BY", context.storedBy);
    }
    if (context.stored_as != null) {
        Identifier name = new Identifier("format");
        String storedAsString = ((Identifier) visit(context.stored_as)).getValue();
        Expression value = new StringLiteral(getFileFormat(storedAsString));
        properties.add(new Property(name, value));
        addDiff(DiffType.MODIFIED, context.STORED_AS(0).getText(), FORMAT, "[STORED AS] is formatted");
    }
    if (context.EXTERNAL() != null) {
        if (context.LOCATION() == null) {
            addDiff(DiffType.UNSUPPORTED, context.EXTERNAL().getText(), "[EXTERNAL] should be used with location");
            throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported statement: 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");
    }
    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");
    }
    if (context.TBLPROPERTIES() != null) {
        List<Property> tblProperties = visit(context.tableProperties.property(), Property.class);
        for (int i = 0; i < tblProperties.size(); i++) {
            Property property = tblProperties.get(i);
            if (property.getName().getValue().equalsIgnoreCase("transactional")) {
                Identifier name = new Identifier("transactional");
                Expression value = new Identifier(unquote(property.getValue().toString()));
                properties.add(new Property(name, value));
                addDiff(DiffType.MODIFIED, property.getName().getValue(), "transactional = ", "[TRANSACTIONAL] is formatted");
            } else {
                addDiff(DiffType.UNSUPPORTED, property.getName().getValue(), "[TBLPROPERTIES] has unsupported properties");
                throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, format("Unsupported attribute: %s", property.getName().getValue()), context.tableProperties);
            }
        }
    }
    return new CreateTable(getLocation(context), getQualifiedName(context.qualifiedName()), elements, context.EXISTS() != null, properties, comment);
}
Also used : ArrayList(java.util.ArrayList) CreateTable(io.prestosql.sql.tree.CreateTable) TableElement(io.prestosql.sql.tree.TableElement) ColumnDefinition(io.prestosql.sql.tree.ColumnDefinition) Identifier(io.prestosql.sql.tree.Identifier) StringLiteral(io.prestosql.sql.tree.StringLiteral) ArithmeticUnaryExpression(io.prestosql.sql.tree.ArithmeticUnaryExpression) 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) ArrayConstructor(io.prestosql.sql.tree.ArrayConstructor) HiveSqlParser(io.hetu.core.migration.source.hive.HiveSqlParser) Property(io.prestosql.sql.tree.Property)

Example 25 with StringLiteral

use of io.prestosql.sql.tree.StringLiteral 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)

Aggregations

StringLiteral (io.prestosql.sql.tree.StringLiteral)47 Test (org.testng.annotations.Test)23 LongLiteral (io.prestosql.sql.tree.LongLiteral)20 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)15 FunctionCall (io.prestosql.sql.tree.FunctionCall)15 Identifier (io.prestosql.sql.tree.Identifier)15 Expression (io.prestosql.sql.tree.Expression)14 Property (io.prestosql.sql.tree.Property)12 ArithmeticBinaryExpression (io.prestosql.sql.tree.ArithmeticBinaryExpression)9 ArithmeticUnaryExpression (io.prestosql.sql.tree.ArithmeticUnaryExpression)9 DereferenceExpression (io.prestosql.sql.tree.DereferenceExpression)9 DoubleLiteral (io.prestosql.sql.tree.DoubleLiteral)9 IfExpression (io.prestosql.sql.tree.IfExpression)9 LogicalBinaryExpression (io.prestosql.sql.tree.LogicalBinaryExpression)9 NotExpression (io.prestosql.sql.tree.NotExpression)9 QuantifiedComparisonExpression (io.prestosql.sql.tree.QuantifiedComparisonExpression)9 SearchedCaseExpression (io.prestosql.sql.tree.SearchedCaseExpression)9 SimpleCaseExpression (io.prestosql.sql.tree.SimpleCaseExpression)9 SubqueryExpression (io.prestosql.sql.tree.SubqueryExpression)9 CoalesceExpression (io.prestosql.sql.tree.CoalesceExpression)8