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();
}
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]"));
}
}
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"))))));
}
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[] {}));
}
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));
}
Aggregations