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);
}
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)));
}
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);
}
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);
}
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);
}
Aggregations