Search in sources :

Example 11 with INTEGER

use of com.facebook.presto.common.type.IntegerType.INTEGER in project presto by prestodb.

the class TestThriftIndexPageSource method testGetNextPageTwoConcurrentRequests.

@Test
public void testGetNextPageTwoConcurrentRequests() throws Exception {
    final int splits = 3;
    final int lookupRequestsConcurrency = 2;
    final int rowsPerSplit = 1;
    List<SettableFuture<PrestoThriftPageResult>> futures = IntStream.range(0, splits).mapToObj(i -> SettableFuture.<PrestoThriftPageResult>create()).collect(toImmutableList());
    List<CountDownLatch> signals = IntStream.range(0, splits).mapToObj(i -> new CountDownLatch(1)).collect(toImmutableList());
    TestingThriftService client = new TestingThriftService(rowsPerSplit, false, false) {

        @Override
        public ListenableFuture<PrestoThriftPageResult> getRows(PrestoThriftId splitId, List<String> columns, long maxBytes, PrestoThriftNullableToken nextToken) {
            int key = Ints.fromByteArray(splitId.getId());
            signals.get(key).countDown();
            return futures.get(key);
        }
    };
    ThriftConnectorStats stats = new ThriftConnectorStats();
    long pageSizeReceived = 0;
    ThriftIndexPageSource pageSource = new ThriftIndexPageSource((context, headers) -> client, ImmutableMap.of(), stats, new ThriftIndexHandle(new SchemaTableName("default", "table1"), TupleDomain.all()), ImmutableList.of(column("a", INTEGER)), ImmutableList.of(column("b", INTEGER)), new InMemoryRecordSet(ImmutableList.of(INTEGER), generateKeys(0, splits)), MAX_BYTES_PER_RESPONSE, lookupRequestsConcurrency);
    assertNull(pageSource.getNextPage());
    assertEquals((long) stats.getIndexPageSize().getAllTime().getTotal(), 0);
    signals.get(0).await(1, SECONDS);
    signals.get(1).await(1, SECONDS);
    signals.get(2).await(1, SECONDS);
    assertEquals(signals.get(0).getCount(), 0, "first request wasn't sent");
    assertEquals(signals.get(1).getCount(), 0, "second request wasn't sent");
    assertEquals(signals.get(2).getCount(), 1, "third request shouldn't be sent");
    // at this point first two requests were sent
    assertFalse(pageSource.isFinished());
    assertNull(pageSource.getNextPage());
    assertEquals((long) stats.getIndexPageSize().getAllTime().getTotal(), 0);
    // completing the second request
    futures.get(1).set(pageResult(20, null));
    Page page = pageSource.getNextPage();
    pageSizeReceived += page.getSizeInBytes();
    assertEquals((long) stats.getIndexPageSize().getAllTime().getTotal(), pageSizeReceived);
    assertNotNull(page);
    assertEquals(page.getPositionCount(), 1);
    assertEquals(page.getBlock(0).getInt(0), 20);
    // not complete yet
    assertFalse(pageSource.isFinished());
    // once one of the requests completes the next one should be sent
    signals.get(2).await(1, SECONDS);
    assertEquals(signals.get(2).getCount(), 0, "third request wasn't sent");
    // completing the first request
    futures.get(0).set(pageResult(10, null));
    page = pageSource.getNextPage();
    assertNotNull(page);
    pageSizeReceived += page.getSizeInBytes();
    assertEquals((long) stats.getIndexPageSize().getAllTime().getTotal(), pageSizeReceived);
    assertEquals(page.getPositionCount(), 1);
    assertEquals(page.getBlock(0).getInt(0), 10);
    // still not complete
    assertFalse(pageSource.isFinished());
    // completing the third request
    futures.get(2).set(pageResult(30, null));
    page = pageSource.getNextPage();
    assertNotNull(page);
    pageSizeReceived += page.getSizeInBytes();
    assertEquals((long) stats.getIndexPageSize().getAllTime().getTotal(), pageSizeReceived);
    assertEquals(page.getPositionCount(), 1);
    assertEquals(page.getBlock(0).getInt(0), 30);
    // finished now
    assertTrue(pageSource.isFinished());
    // after completion
    assertNull(pageSource.getNextPage());
    pageSource.close();
}
Also used : SettableFuture(com.google.common.util.concurrent.SettableFuture) IntStream(java.util.stream.IntStream) Collections.shuffle(java.util.Collections.shuffle) PrestoThriftNullableSchemaName(com.facebook.presto.thrift.api.connector.PrestoThriftNullableSchemaName) Page(com.facebook.presto.common.Page) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Assert.assertNull(org.testng.Assert.assertNull) PrestoThriftNullableTableMetadata(com.facebook.presto.thrift.api.connector.PrestoThriftNullableTableMetadata) PrestoThriftNullableColumnSet(com.facebook.presto.thrift.api.connector.PrestoThriftNullableColumnSet) PrestoThriftBlock.integerData(com.facebook.presto.thrift.api.datatypes.PrestoThriftBlock.integerData) Assert.assertEquals(org.testng.Assert.assertEquals) PrestoThriftSplitBatch(com.facebook.presto.thrift.api.connector.PrestoThriftSplitBatch) Test(org.testng.annotations.Test) CompletableFuture(java.util.concurrent.CompletableFuture) SettableFuture(com.google.common.util.concurrent.SettableFuture) PrestoThriftPageResult(com.facebook.presto.thrift.api.connector.PrestoThriftPageResult) InMemoryRecordSet(com.facebook.presto.spi.InMemoryRecordSet) ArrayList(java.util.ArrayList) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableList(com.google.common.collect.ImmutableList) PrestoThriftSchemaTableName(com.facebook.presto.thrift.api.connector.PrestoThriftSchemaTableName) PrestoThriftNullableToken(com.facebook.presto.thrift.api.connector.PrestoThriftNullableToken) PrestoThriftTupleDomain(com.facebook.presto.thrift.api.connector.PrestoThriftTupleDomain) Assert.assertFalse(org.testng.Assert.assertFalse) Type(com.facebook.presto.common.type.Type) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) PrestoThriftService(com.facebook.presto.thrift.api.connector.PrestoThriftService) PrestoThriftServiceException(com.facebook.presto.thrift.api.connector.PrestoThriftServiceException) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Assert.assertNotNull(org.testng.Assert.assertNotNull) PrestoThriftId(com.facebook.presto.thrift.api.connector.PrestoThriftId) PrestoThriftSplit(com.facebook.presto.thrift.api.connector.PrestoThriftSplit) Ints(com.google.common.primitives.Ints) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) PrestoThriftInteger(com.facebook.presto.thrift.api.datatypes.PrestoThriftInteger) Assert.assertTrue(org.testng.Assert.assertTrue) Block(com.facebook.presto.common.block.Block) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) PrestoThriftId(com.facebook.presto.thrift.api.connector.PrestoThriftId) PrestoThriftNullableToken(com.facebook.presto.thrift.api.connector.PrestoThriftNullableToken) PrestoThriftPageResult(com.facebook.presto.thrift.api.connector.PrestoThriftPageResult) Page(com.facebook.presto.common.Page) CountDownLatch(java.util.concurrent.CountDownLatch) SchemaTableName(com.facebook.presto.spi.SchemaTableName) PrestoThriftSchemaTableName(com.facebook.presto.thrift.api.connector.PrestoThriftSchemaTableName) InMemoryRecordSet(com.facebook.presto.spi.InMemoryRecordSet) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) Test(org.testng.annotations.Test)

Example 12 with INTEGER

use of com.facebook.presto.common.type.IntegerType.INTEGER in project presto by prestodb.

the class TestCassandraIntegrationSmokeTest method assertSelect.

private void assertSelect(String tableName, boolean createdByPresto) {
    Type uuidType = createdByPresto ? createUnboundedVarcharType() : createVarcharType(36);
    Type inetType = createdByPresto ? createUnboundedVarcharType() : createVarcharType(45);
    String sql = "SELECT " + " key, " + " typeuuid, " + " typeinteger, " + " typelong, " + " typebytes, " + " typetimestamp, " + " typeansi, " + " typeboolean, " + " typedecimal, " + " typedouble, " + " typefloat, " + " typeinet, " + " typevarchar, " + " typevarint, " + " typetimeuuid, " + " typelist, " + " typemap, " + " typeset " + " FROM " + tableName;
    MaterializedResult result = execute(sql);
    int rowCount = result.getRowCount();
    assertEquals(rowCount, 9);
    assertEquals(result.getTypes(), ImmutableList.of(createUnboundedVarcharType(), uuidType, INTEGER, BIGINT, VARBINARY, TIMESTAMP, createUnboundedVarcharType(), BOOLEAN, DOUBLE, DOUBLE, REAL, inetType, createUnboundedVarcharType(), createUnboundedVarcharType(), uuidType, createUnboundedVarcharType(), createUnboundedVarcharType(), createUnboundedVarcharType()));
    List<MaterializedRow> sortedRows = result.getMaterializedRows().stream().sorted((o1, o2) -> o1.getField(1).toString().compareTo(o2.getField(1).toString())).collect(toList());
    for (int rowNumber = 1; rowNumber <= rowCount; rowNumber++) {
        assertEquals(sortedRows.get(rowNumber - 1), new MaterializedRow(DEFAULT_PRECISION, "key " + rowNumber, String.format("00000000-0000-0000-0000-%012d", rowNumber), rowNumber, rowNumber + 1000L, ByteBuffer.wrap(toByteArray(rowNumber)), TIMESTAMP_LOCAL, "ansi " + rowNumber, rowNumber % 2 == 0, Math.pow(2, rowNumber), Math.pow(4, rowNumber), (float) Math.pow(8, rowNumber), "127.0.0.1", "varchar " + rowNumber, BigInteger.TEN.pow(rowNumber).toString(), String.format("d2177dd0-eaa2-11de-a572-001b779c76e%d", rowNumber), String.format("[\"list-value-1%1$d\",\"list-value-2%1$d\"]", rowNumber), String.format("{%d:%d,%d:%d}", rowNumber, rowNumber + 1L, rowNumber + 2, rowNumber + 3L), "[false,true]"));
    }
}
Also used : TABLE_CLUSTERING_KEYS_INEQUALITY(com.facebook.presto.cassandra.CassandraTestingUtils.TABLE_CLUSTERING_KEYS_INEQUALITY) VarcharType.createUnboundedVarcharType(com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType) LocalDateTime(java.time.LocalDateTime) TABLE_ALL_TYPES(com.facebook.presto.cassandra.CassandraTestingUtils.TABLE_ALL_TYPES) MaterializedResult.resultBuilder(com.facebook.presto.testing.MaterializedResult.resultBuilder) Assert.assertEquals(org.testng.Assert.assertEquals) QueryRunner(com.facebook.presto.testing.QueryRunner) Test(org.testng.annotations.Test) TIMESTAMP(com.facebook.presto.common.type.TimestampType.TIMESTAMP) MINUTES(java.util.concurrent.TimeUnit.MINUTES) VarcharType.createVarcharType(com.facebook.presto.common.type.VarcharType.createVarcharType) ByteBuffer(java.nio.ByteBuffer) REAL(com.facebook.presto.common.type.RealType.REAL) Duration(io.airlift.units.Duration) Bytes.toRawHexString(com.datastax.driver.core.utils.Bytes.toRawHexString) DEFAULT_PRECISION(com.facebook.presto.testing.MaterializedResult.DEFAULT_PRECISION) ImmutableList(com.google.common.collect.ImmutableList) QueryAssertions.assertContains(com.facebook.presto.tests.QueryAssertions.assertContains) TABLE_ALL_TYPES_PARTITION_KEY(com.facebook.presto.cassandra.CassandraTestingUtils.TABLE_ALL_TYPES_PARTITION_KEY) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) BigInteger(java.math.BigInteger) Ints.toByteArray(com.google.common.primitives.Ints.toByteArray) Type(com.facebook.presto.common.type.Type) CassandraQueryRunner.createCassandraQueryRunner(com.facebook.presto.cassandra.CassandraQueryRunner.createCassandraQueryRunner) TABLE_ALL_TYPES_INSERT(com.facebook.presto.cassandra.CassandraTestingUtils.TABLE_ALL_TYPES_INSERT) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) TABLE_CLUSTERING_KEYS_LARGE(com.facebook.presto.cassandra.CassandraTestingUtils.TABLE_CLUSTERING_KEYS_LARGE) Session(com.facebook.presto.Session) BeforeClass(org.testng.annotations.BeforeClass) Timestamp(java.sql.Timestamp) TABLE_CLUSTERING_KEYS(com.facebook.presto.cassandra.CassandraTestingUtils.TABLE_CLUSTERING_KEYS) VARBINARY(com.facebook.presto.common.type.VarbinaryType.VARBINARY) CassandraQueryRunner.createCassandraSession(com.facebook.presto.cassandra.CassandraQueryRunner.createCassandraSession) CassandraTestingUtils.createTestTables(com.facebook.presto.cassandra.CassandraTestingUtils.createTestTables) MaterializedResult(com.facebook.presto.testing.MaterializedResult) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) MaterializedRow(com.facebook.presto.testing.MaterializedRow) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) TABLE_MULTI_PARTITION_CLUSTERING_KEYS(com.facebook.presto.cassandra.CassandraTestingUtils.TABLE_MULTI_PARTITION_CLUSTERING_KEYS) AbstractTestIntegrationSmokeTest(com.facebook.presto.tests.AbstractTestIntegrationSmokeTest) QueryAssertions.assertContainsEventually(com.facebook.presto.tests.QueryAssertions.assertContainsEventually) VarcharType.createUnboundedVarcharType(com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType) VarcharType.createVarcharType(com.facebook.presto.common.type.VarcharType.createVarcharType) Type(com.facebook.presto.common.type.Type) Bytes.toRawHexString(com.datastax.driver.core.utils.Bytes.toRawHexString) MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow)

Example 13 with INTEGER

use of com.facebook.presto.common.type.IntegerType.INTEGER in project presto by prestodb.

the class TestPredicatePushdown method testPredicatePushDownCreatesValidJoin.

@Test
public void testPredicatePushDownCreatesValidJoin() {
    RuleTester tester = new RuleTester();
    tester.assertThat(new PredicatePushDown(tester.getMetadata(), tester.getSqlParser())).on(p -> p.join(INNER, p.filter(p.comparison(OperatorType.EQUAL, p.variable("a1"), constant(1L, INTEGER)), p.values(p.variable("a1"))), p.values(p.variable("b1")), ImmutableList.of(new EquiJoinClause(p.variable("a1"), p.variable("b1"))), ImmutableList.of(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(PARTITIONED), ImmutableMap.of())).matches(project(join(INNER, ImmutableList.of(), Optional.empty(), Optional.of(REPLICATED), project(filter("a1=1", values("a1"))), project(filter("1=b1", values("b1"))))));
}
Also used : EquiJoinClause(com.facebook.presto.sql.planner.plan.JoinNode.EquiJoinClause) PlanOptimizer(com.facebook.presto.sql.planner.optimizations.PlanOptimizer) PlanMatchPattern.filter(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.filter) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) PredicatePushDown(com.facebook.presto.sql.planner.optimizations.PredicatePushDown) PlanMatchPattern.anyTree(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.anyTree) PlanMatchPattern.output(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.output) PlanMatchPattern.assignUniqueId(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.assignUniqueId) Test(org.testng.annotations.Test) Expressions.constant(com.facebook.presto.sql.relational.Expressions.constant) PlanMatchPattern(com.facebook.presto.sql.planner.assertions.PlanMatchPattern) PlanMatchPattern.join(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.join) ImmutableList(com.google.common.collect.ImmutableList) PlanMatchPattern.equiJoinClause(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.equiJoinClause) Map(java.util.Map) PlanMatchPattern.expression(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.expression) PlanMatchPattern.project(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.project) WindowNode(com.facebook.presto.sql.planner.plan.WindowNode) ImmutableMap(com.google.common.collect.ImmutableMap) PlanMatchPattern.semiJoin(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.semiJoin) PlanMatchPattern.tableScan(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.tableScan) PlanMatchPattern.exchange(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.exchange) OperatorType(com.facebook.presto.common.function.OperatorType) List(java.util.List) REPLICATED(com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.REPLICATED) LEFT(com.facebook.presto.sql.planner.plan.JoinNode.Type.LEFT) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) Optional(java.util.Optional) PlanMatchPattern.values(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values) PARTITIONED(com.facebook.presto.sql.planner.plan.JoinNode.DistributionType.PARTITIONED) RuleTester(com.facebook.presto.sql.planner.iterative.rule.test.RuleTester) ExchangeNode(com.facebook.presto.sql.planner.plan.ExchangeNode) PlanMatchPattern.node(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.node) INNER(com.facebook.presto.sql.planner.plan.JoinNode.Type.INNER) RuleTester(com.facebook.presto.sql.planner.iterative.rule.test.RuleTester) EquiJoinClause(com.facebook.presto.sql.planner.plan.JoinNode.EquiJoinClause) PredicatePushDown(com.facebook.presto.sql.planner.optimizations.PredicatePushDown) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 14 with INTEGER

use of com.facebook.presto.common.type.IntegerType.INTEGER in project presto by prestodb.

the class PagesSpatialIndexSupplier method buildRTree.

private static Flatbush<GeometryWithPosition> buildRTree(AdaptiveLongBigArray addresses, int positionCount, List<List<Block>> channels, int geometryChannel, Optional<Integer> radiusChannel, Optional<Integer> partitionChannel, LocalMemoryContext localUserMemoryContext) {
    Operator relateOperator = OperatorFactoryLocal.getInstance().getOperator(Operator.Type.Relate);
    ObjectArrayList<GeometryWithPosition> geometries = new ObjectArrayList<>();
    long recordedSizeInBytes = localUserMemoryContext.getBytes();
    long addedSizeInBytes = 0;
    for (int position = 0; position < positionCount; position++) {
        long pageAddress = addresses.get(position);
        int blockIndex = decodeSliceIndex(pageAddress);
        int blockPosition = decodePosition(pageAddress);
        Block block = channels.get(geometryChannel).get(blockIndex);
        // TODO Consider pushing is-null and is-empty checks into a filter below the join
        if (block.isNull(blockPosition)) {
            continue;
        }
        Slice slice = block.getSlice(blockPosition, 0, block.getSliceLength(blockPosition));
        OGCGeometry ogcGeometry = deserialize(slice);
        verify(ogcGeometry != null);
        if (ogcGeometry.isEmpty()) {
            continue;
        }
        double radius = radiusChannel.map(channel -> DOUBLE.getDouble(channels.get(channel).get(blockIndex), blockPosition)).orElse(0.0);
        if (radius < 0) {
            continue;
        }
        if (!radiusChannel.isPresent()) {
            // If radiusChannel is supplied, this is a distance query, for which our acceleration won't help.
            accelerateGeometry(ogcGeometry, relateOperator);
        }
        int partition = -1;
        if (partitionChannel.isPresent()) {
            Block partitionBlock = channels.get(partitionChannel.get()).get(blockIndex);
            partition = toIntExact(INTEGER.getLong(partitionBlock, blockPosition));
        }
        GeometryWithPosition geometryWithPosition = new GeometryWithPosition(ogcGeometry, partition, position, radius);
        geometries.add(geometryWithPosition);
        addedSizeInBytes += geometryWithPosition.getEstimatedSizeInBytes();
        if (addedSizeInBytes >= MEMORY_USAGE_UPDATE_INCREMENT_BYTES) {
            localUserMemoryContext.setBytes(recordedSizeInBytes + addedSizeInBytes);
            recordedSizeInBytes += addedSizeInBytes;
            addedSizeInBytes = 0;
        }
    }
    return new Flatbush<>(geometries.toArray(new GeometryWithPosition[] {}));
}
Also used : Operator(com.esri.core.geometry.Operator) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) Slice(io.airlift.slice.Slice) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) ObjectArrayList(it.unimi.dsi.fastutil.objects.ObjectArrayList) Supplier(java.util.function.Supplier) Verify.verify(com.google.common.base.Verify.verify) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) AdaptiveLongBigArray(com.facebook.presto.common.array.AdaptiveLongBigArray) Math.toIntExact(java.lang.Math.toIntExact) SyntheticAddress.decodePosition(com.facebook.presto.operator.SyntheticAddress.decodePosition) Type(com.facebook.presto.common.type.Type) Operator(com.esri.core.geometry.Operator) OperatorFactoryLocal(com.esri.core.geometry.OperatorFactoryLocal) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) Session(com.facebook.presto.Session) LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext) JoinFilterFunctionCompiler(com.facebook.presto.sql.gen.JoinFilterFunctionCompiler) Flatbush(com.facebook.presto.geospatial.rtree.Flatbush) Rectangle(com.facebook.presto.geospatial.Rectangle) DataSize(io.airlift.units.DataSize) List(java.util.List) ClassLayout(org.openjdk.jol.info.ClassLayout) EsriGeometrySerde.deserialize(com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserialize) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) SyntheticAddress.decodeSliceIndex(com.facebook.presto.operator.SyntheticAddress.decodeSliceIndex) GeometryUtils.accelerateGeometry(com.facebook.presto.geospatial.GeometryUtils.accelerateGeometry) Optional(java.util.Optional) EMPTY_INDEX(com.facebook.presto.operator.PagesSpatialIndex.EMPTY_INDEX) Block(com.facebook.presto.common.block.Block) BYTE(io.airlift.units.DataSize.Unit.BYTE) SpatialPredicate(com.facebook.presto.operator.SpatialIndexBuilderOperator.SpatialPredicate) GeometryWithPosition(com.facebook.presto.operator.PagesRTreeIndex.GeometryWithPosition) ObjectArrayList(it.unimi.dsi.fastutil.objects.ObjectArrayList) GeometryWithPosition(com.facebook.presto.operator.PagesRTreeIndex.GeometryWithPosition) Slice(io.airlift.slice.Slice) Block(com.facebook.presto.common.block.Block) Flatbush(com.facebook.presto.geospatial.rtree.Flatbush)

Example 15 with INTEGER

use of com.facebook.presto.common.type.IntegerType.INTEGER in project presto by prestodb.

the class TestTranslateExpressions method testTranslateIntermediateAggregationWithLambda.

@Test
public void testTranslateIntermediateAggregationWithLambda() {
    PlanNode result = tester().assertThat(new TranslateExpressions(METADATA, new SqlParser()).aggregationRowExpressionRewriteRule()).on(p -> p.aggregation(builder -> builder.globalGrouping().addAggregation(variable("reduce_agg", INTEGER), new AggregationNode.Aggregation(new CallExpression("reduce_agg", REDUCE_AGG, INTEGER, ImmutableList.of(castToRowExpression(expression("input")), castToRowExpression(expression("(x,y) -> x*y")), castToRowExpression(expression("(a,b) -> a*b")))), Optional.of(castToRowExpression(expression("input > 10"))), Optional.empty(), false, Optional.empty())).source(p.values(p.variable("input", INTEGER))))).get();
    AggregationNode.Aggregation translated = ((AggregationNode) result).getAggregations().get(variable("reduce_agg", INTEGER));
    assertEquals(translated, new AggregationNode.Aggregation(new CallExpression("reduce_agg", REDUCE_AGG, INTEGER, ImmutableList.of(variable("input", INTEGER), new LambdaDefinitionExpression(Optional.empty(), ImmutableList.of(INTEGER, INTEGER), ImmutableList.of("x", "y"), multiply(variable("x", INTEGER), variable("y", INTEGER))), new LambdaDefinitionExpression(Optional.empty(), ImmutableList.of(INTEGER, INTEGER), ImmutableList.of("a", "b"), multiply(variable("a", INTEGER), variable("b", INTEGER))))), Optional.of(greaterThan(variable("input", INTEGER), constant(10L, INTEGER))), Optional.empty(), false, Optional.empty()));
    assertFalse(isUntranslated(translated));
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) OriginalExpressionUtils(com.facebook.presto.sql.relational.OriginalExpressionUtils) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) TypeSignatureProvider.fromTypes(com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypes) Expressions.call(com.facebook.presto.sql.relational.Expressions.call) Expressions.constant(com.facebook.presto.sql.relational.Expressions.constant) ImmutableList(com.google.common.collect.ImmutableList) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution) Expressions.variable(com.facebook.presto.sql.relational.Expressions.variable) CallExpression(com.facebook.presto.spi.relation.CallExpression) Assert.assertFalse(org.testng.Assert.assertFalse) RowExpression(com.facebook.presto.spi.relation.RowExpression) LambdaDefinitionExpression(com.facebook.presto.spi.relation.LambdaDefinitionExpression) OperatorType(com.facebook.presto.common.function.OperatorType) FunctionType(com.facebook.presto.common.type.FunctionType) SqlParser(com.facebook.presto.sql.parser.SqlParser) PlanNode(com.facebook.presto.spi.plan.PlanNode) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest) MetadataManager.createTestMetadataManager(com.facebook.presto.metadata.MetadataManager.createTestMetadataManager) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) Optional(java.util.Optional) PlanBuilder.expression(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder.expression) Metadata(com.facebook.presto.metadata.Metadata) OriginalExpressionUtils.castToRowExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.castToRowExpression) PlanNode(com.facebook.presto.spi.plan.PlanNode) SqlParser(com.facebook.presto.sql.parser.SqlParser) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) CallExpression(com.facebook.presto.spi.relation.CallExpression) LambdaDefinitionExpression(com.facebook.presto.spi.relation.LambdaDefinitionExpression) Test(org.testng.annotations.Test) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest)

Aggregations

INTEGER (com.facebook.presto.common.type.IntegerType.INTEGER)28 ImmutableList (com.google.common.collect.ImmutableList)26 List (java.util.List)25 Type (com.facebook.presto.common.type.Type)23 Optional (java.util.Optional)22 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)19 Map (java.util.Map)19 Test (org.testng.annotations.Test)19 BOOLEAN (com.facebook.presto.common.type.BooleanType.BOOLEAN)18 ImmutableMap (com.google.common.collect.ImmutableMap)18 Page (com.facebook.presto.common.Page)17 DOUBLE (com.facebook.presto.common.type.DoubleType.DOUBLE)17 ArrayList (java.util.ArrayList)17 Assert.assertEquals (org.testng.Assert.assertEquals)17 REAL (com.facebook.presto.common.type.RealType.REAL)15 SMALLINT (com.facebook.presto.common.type.SmallintType.SMALLINT)15 Block (com.facebook.presto.common.block.Block)14 DATE (com.facebook.presto.common.type.DateType.DATE)14 VARCHAR (com.facebook.presto.common.type.VarcharType.VARCHAR)14 Collectors.toList (java.util.stream.Collectors.toList)14