use of com.facebook.presto.sql.tree.DereferenceExpression in project presto by prestodb.
the class TestSqlParser method testSelectWithRowType.
@Test
public void testSelectWithRowType() {
assertStatement("SELECT col1.f1, col2, col3.f1.f2.f3 FROM table1", new Query(Optional.empty(), new QuerySpecification(selectList(new DereferenceExpression(new Identifier("col1"), identifier("f1")), new Identifier("col2"), new DereferenceExpression(new DereferenceExpression(new DereferenceExpression(new Identifier("col3"), identifier("f1")), identifier("f2")), identifier("f3"))), Optional.of(new Table(QualifiedName.of("table1"))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()), Optional.empty(), Optional.empty(), Optional.empty()));
assertStatement("SELECT col1.f1[0], col2, col3[2].f2.f3, col4[4] FROM table1", new Query(Optional.empty(), new QuerySpecification(selectList(new SubscriptExpression(new DereferenceExpression(new Identifier("col1"), identifier("f1")), new LongLiteral("0")), new Identifier("col2"), new DereferenceExpression(new DereferenceExpression(new SubscriptExpression(new Identifier("col3"), new LongLiteral("2")), identifier("f2")), identifier("f3")), new SubscriptExpression(new Identifier("col4"), new LongLiteral("4"))), Optional.of(new Table(QualifiedName.of("table1"))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()), Optional.empty(), Optional.empty(), Optional.empty()));
assertStatement("SELECT CAST(ROW(11, 12) AS ROW(COL0 INTEGER, COL1 INTEGER)).col0", new Query(Optional.empty(), new QuerySpecification(selectList(new DereferenceExpression(new Cast(new Row(Lists.newArrayList(new LongLiteral("11"), new LongLiteral("12"))), "ROW(COL0 INTEGER,COL1 INTEGER)"), identifier("col0"))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()), Optional.empty(), Optional.empty(), Optional.empty()));
}
use of com.facebook.presto.sql.tree.DereferenceExpression in project presto by prestodb.
the class TestSqlParser method testAggregationWithOrderBy.
@Test
public void testAggregationWithOrderBy() {
assertExpression("array_agg(x ORDER BY x DESC)", new FunctionCall(QualifiedName.of("array_agg"), Optional.empty(), Optional.empty(), Optional.of(new OrderBy(ImmutableList.of(new SortItem(identifier("x"), DESCENDING, UNDEFINED)))), false, ImmutableList.of(identifier("x"))));
assertStatement("SELECT array_agg(x ORDER BY t.y) FROM t", new Query(Optional.empty(), new QuerySpecification(selectList(new FunctionCall(QualifiedName.of("array_agg"), Optional.empty(), Optional.empty(), Optional.of(new OrderBy(ImmutableList.of(new SortItem(new DereferenceExpression(new Identifier("t"), identifier("y")), ASCENDING, UNDEFINED)))), false, ImmutableList.of(new Identifier("x")))), Optional.of(table(QualifiedName.of("t"))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()), Optional.empty(), Optional.empty(), Optional.empty()));
}
use of com.facebook.presto.sql.tree.DereferenceExpression in project presto by prestodb.
the class RelationPlanner method rewriteRow.
private RowExpression rewriteRow(Expression row) {
// resolve enum literals
Expression expression = ExpressionTreeRewriter.rewriteWith(new ExpressionRewriter<Void>() {
@Override
public Expression rewriteDereferenceExpression(DereferenceExpression node, Void context, ExpressionTreeRewriter<Void> treeRewriter) {
Type baseType = analysis.getType(node.getBase());
Type nodeType = analysis.getType(node);
if (isEnumType(baseType) && isEnumType(nodeType)) {
return new EnumLiteral(nodeType.getTypeSignature().toString(), resolveEnumLiteral(node, nodeType));
}
return node;
}
}, row);
expression = Coercer.addCoercions(expression, analysis);
expression = ExpressionTreeRewriter.rewriteWith(new ParameterRewriter(analysis.getParameters(), analysis), expression);
return castToRowExpression(expression);
}
use of com.facebook.presto.sql.tree.DereferenceExpression in project presto by prestodb.
the class TestChecksumValidator method testRow.
@Test
public void testRow() {
List<Column> columns = ImmutableList.of(ROW_COLUMN);
ChecksumResult controlChecksum = new ChecksumResult(ROW_COLUMN_CHECKSUMS.size(), ROW_COLUMN_CHECKSUMS);
assertTrue(checksumValidator.getMismatchedColumns(columns, controlChecksum, controlChecksum).isEmpty());
// Mismatched different elements
ChecksumResult testChecksum = new ChecksumResult(ROW_COLUMN_CHECKSUMS.size(), merge(ROW_COLUMN_CHECKSUMS, ImmutableMap.<String, Object>builder().put("row.i$checksum", new SqlVarbinary(new byte[] { 0x1a })).put("row.r.b$checksum", new SqlVarbinary(new byte[] { 0x1d })).build()));
Column aFieldColumn = Column.create("row.i", new DereferenceExpression(ROW_COLUMN.getExpression(), new Identifier("i")), INTEGER);
Column rbFieldColumn = Column.create("row.r.b", new DereferenceExpression(new DereferenceExpression(ROW_COLUMN.getExpression(), new Identifier("r")), new Identifier("b")), BIGINT);
assertMismatchedColumns(columns, controlChecksum, testChecksum, aFieldColumn, rbFieldColumn);
}
Aggregations