Search in sources :

Example 11 with Property

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

the class ImpalaAstBuilder method visitCreateTable.

@Override
public Node visitCreateTable(ImpalaSqlParser.CreateTableContext context) {
    Optional<String> comment = Optional.empty();
    if (context.COMMENT() != null) {
        comment = Optional.of(((StringLiteral) visit(context.comment)).getValue());
    }
    List<Property> properties = new ArrayList<>();
    // external table
    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");
    }
    // handle partitioned by
    List<TableElement> elements = getTableElements(context.tableElement());
    if (context.AS() == null && elements.size() == 0) {
        throw unsupportedError(ErrorType.SYNTAX_ERROR, "Create table should specify at least one column.", context);
    }
    if (context.PARTITIONED() != null) {
        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()));
            // add the partitioned_by column to table columns
            elements.add(new ColumnDefinition(iter.getName(), iter.getType(), true, emptyList(), Optional.empty()));
        }
        Expression value = new ArrayConstructor(expressions);
        properties.add(new Property(new Identifier(PARTITIONED_BY), value));
        addDiff(DiffType.MODIFIED, context.PARTITIONED().getText(), PARTITIONED_BY, "[partitioned by] is formatted");
    }
    // handle sort by
    if (context.SORT() != null) {
        List<Expression> quotedExpressions = new ArrayList<>();
        List<Expression> expressions = getExpressions(context.sortedBy().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(new Identifier(SORTED_BY), value));
        addDiff(DiffType.MODIFIED, context.SORT().getText(), SORTED_BY, "[sorted by] is formatted");
    }
    // row format
    if (context.ROW() != null && context.FORMAT() != null) {
        addDiff(DiffType.UNSUPPORTED, context.ROW().getText(), "[ROW FORMAT] is not supported");
        addDiff(DiffType.UNSUPPORTED, context.FORMAT().getText(), null);
        throw unsupportedError(ErrorType.UNSUPPORTED_KEYWORDS, "ROW FORMAT", context);
    }
    // serde properties
    if (context.SERDEPROPERTIES() != null) {
        addDiff(DiffType.UNSUPPORTED, context.SERDEPROPERTIES().getText(), "[WITH SERDEPROPERTIES] is not supported");
        throw unsupportedError(ErrorType.UNSUPPORTED_KEYWORDS, "WITH SERDEPROPERTIES", context);
    }
    // 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");
    }
    // location
    if (context.LOCATION() != null) {
        Expression value = (StringLiteral) visit(context.location);
        properties.add(new Property(new Identifier(LOCATION), value));
        addDiff(DiffType.MODIFIED, context.LOCATION().getText(), LOCATION + " = " + value, "[location] is formatted");
    }
    // cached in
    if (context.CACHED() != null) {
        addDiff(DiffType.UNSUPPORTED, context.CACHED().getText(), "[CACHED IN] is not supported");
        throw unsupportedError(ErrorType.UNSUPPORTED_KEYWORDS, "CACHED IN", context);
    }
    // table properties
    if (context.TBLPROPERTIES() != null) {
        List<Property> tblProperties = visit(context.tblProp.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_ATTRIBUTE, property.getName().getValue(), context.tblProp);
            }
        }
    }
    // create table as
    if (context.AS() != null) {
        return new CreateTableAsSelect(getLocation(context), getQualifiedName(context.tblName), (Query) visit(context.query()), context.EXISTS() != null, properties, true, Optional.empty(), comment);
    }
    return new CreateTable(getLocation(context), getQualifiedName(context.tblName), 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) 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) CreateTableAsSelect(io.prestosql.sql.tree.CreateTableAsSelect) ArrayConstructor(io.prestosql.sql.tree.ArrayConstructor) Property(io.prestosql.sql.tree.Property)

Example 12 with Property

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

the class QueryPlanner method updateIndex.

private PlanBuilder updateIndex(PlanBuilder subPlan, Statement originalStatement) {
    if (!(originalStatement instanceof UpdateIndex)) {
        return subPlan;
    }
    // rewrite sub queries
    UpdateIndex updateIndex = (UpdateIndex) originalStatement;
    Map<String, Type> columnTypes = new HashMap<>();
    for (Field field : analysis.getRootScope().getRelationType().getAllFields()) {
        columnTypes.put(field.getOriginColumnName().get(), field.getType());
    }
    Properties indexProperties = new Properties();
    for (Property property : updateIndex.getProperties()) {
        String key = extractPropertyValue(property.getName());
        String val = extractPropertyValue(property.getValue()).toUpperCase(Locale.ENGLISH);
        indexProperties.setProperty(key, val);
    }
    return subPlan.withNewRoot(new UpdateIndexNode(idAllocator.getNextId(), ExchangeNode.gatheringExchange(idAllocator.getNextId(), ExchangeNode.Scope.REMOTE, subPlan.getRoot()), new UpdateIndexMetadata(updateIndex.getIndexName().toString(), indexProperties, session.getUser(), columnTypes)));
}
Also used : Field(io.prestosql.sql.analyzer.Field) FrameBoundType(io.prestosql.spi.sql.expression.Types.FrameBoundType) Type(io.prestosql.spi.type.Type) WindowFrameType(io.prestosql.spi.sql.expression.Types.WindowFrameType) RelationType(io.prestosql.sql.analyzer.RelationType) UpdateIndexNode(io.prestosql.sql.planner.plan.UpdateIndexNode) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) UpdateIndexMetadata(io.prestosql.spi.connector.UpdateIndexMetadata) UpdateIndex(io.prestosql.sql.tree.UpdateIndex) Properties(java.util.Properties) Property(io.prestosql.sql.tree.Property)

Example 13 with Property

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

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

Example 15 with Property

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

Aggregations

Property (io.prestosql.sql.tree.Property)17 Identifier (io.prestosql.sql.tree.Identifier)14 StringLiteral (io.prestosql.sql.tree.StringLiteral)12 ArrayList (java.util.ArrayList)9 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)8 QuantifiedComparisonExpression (io.prestosql.sql.tree.QuantifiedComparisonExpression)7 ArithmeticBinaryExpression (io.prestosql.sql.tree.ArithmeticBinaryExpression)6 ArithmeticUnaryExpression (io.prestosql.sql.tree.ArithmeticUnaryExpression)6 CoalesceExpression (io.prestosql.sql.tree.CoalesceExpression)6 DereferenceExpression (io.prestosql.sql.tree.DereferenceExpression)6 Expression (io.prestosql.sql.tree.Expression)6 IfExpression (io.prestosql.sql.tree.IfExpression)6 InListExpression (io.prestosql.sql.tree.InListExpression)6 LogicalBinaryExpression (io.prestosql.sql.tree.LogicalBinaryExpression)6 NotExpression (io.prestosql.sql.tree.NotExpression)6 NullIfExpression (io.prestosql.sql.tree.NullIfExpression)6 SearchedCaseExpression (io.prestosql.sql.tree.SearchedCaseExpression)6 SimpleCaseExpression (io.prestosql.sql.tree.SimpleCaseExpression)6 SubqueryExpression (io.prestosql.sql.tree.SubqueryExpression)6 SubscriptExpression (io.prestosql.sql.tree.SubscriptExpression)6