Refine search
@Override Integer offset(Integer origin, long distance) { checkNonnegative(distance, "distance"); return Ints.checkedCast(origin.longValue() + distance); }
public void testAsList_subList_toArray_roundTrip() { int[] array = {(int) 0, (int) 1, (int) 2, (int) 3}; List<Integer> list = Ints.asList(array); assertTrue(Arrays.equals(new int[] {(int) 1, (int) 2}, Ints.toArray(list.subList(1, 3)))); assertTrue(Arrays.equals(new int[] {}, Ints.toArray(list.subList(2, 2)))); }
public void testByteArrayRoundTrips() { Random r = new Random(5); byte[] b = new byte[Ints.BYTES]; // total overkill, but, it takes 0.1 sec so why not... for (int i = 0; i < 10000; i++) { int num = r.nextInt(); assertEquals(num, Ints.fromByteArray(Ints.toByteArray(num))); r.nextBytes(b); assertTrue(Arrays.equals(b, Ints.toByteArray(Ints.fromByteArray(b)))); } }
@Test public void testPartiallyPreGroupedPartitionWithEmptyInput() { List<Page> input = rowPagesBuilder(BIGINT, VARCHAR, BIGINT, VARCHAR) .pageBreak() .pageBreak() .build(); WindowOperatorFactory operatorFactory = createFactoryUnbounded( ImmutableList.of(BIGINT, VARCHAR, BIGINT, VARCHAR), Ints.asList(0, 1, 2, 3), ROW_NUMBER, Ints.asList(0, 1), Ints.asList(1), Ints.asList(3), ImmutableList.of(SortOrder.ASC_NULLS_LAST), 0); MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, VARCHAR, BIGINT, VARCHAR, BIGINT) .build(); assertOperatorEquals(operatorFactory, driverContext, input, expected); }
RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, Ints.asList(0), BIGINT, DOUBLE); List<Page> input = rowPagesBuilder .row(1L, 0.3) 0, new PlanNodeId("test"), ImmutableList.of(BIGINT, DOUBLE), Ints.asList(1, 0), Ints.asList(0), ImmutableList.of(BIGINT), Optional.of(3), Optional.empty(), 10, joinCompiler); .build(); .build(); assertEquals(rowNumberColumn.getPositionCount(), 8); assertTrue(rowNumberColumn.getLong(i, 0) <= 3); MaterializedResult actual = toMaterializedResult(driverContext.getSession(), ImmutableList.of(DOUBLE, BIGINT), pages); assertEquals(Sets.intersection(expectedPartition1Set, actualSet).size(), 3);
@Test public void testYield() RowPagesBuilder buildPages = rowPagesBuilder(true, Ints.asList(0), ImmutableList.of(BIGINT)) .addSequencePage(entries, 42); BuildSideSetup buildSideSetup = setupBuildSide(true, taskContext, Ints.asList(0), buildPages, Optional.of(filterFunction), false, SINGLE_STREAM_SPILLER_FACTORY); JoinBridgeManager<PartitionedLookupSourceFactory> lookupSourceFactory = buildSideSetup.getLookupSourceFactoryManager(); RowPagesBuilder probePages = rowPagesBuilder(false, Ints.asList(0), ImmutableList.of(BIGINT)); List<Page> probeInput = probePages.addSequencePage(100, 0).build(); OperatorFactory joinOperatorFactory = LOOKUP_JOIN_OPERATORS.innerJoin( lookupSourceFactory, probePages.getTypes(), Ints.asList(0), getHashChannelAsInt(probePages), Optional.empty(), OptionalInt.of(1), PARTITIONING_SPILLER_FACTORY); output = operator.getOutput(); assertNotNull(output); driverContext.getYieldSignal().reset();
public StreamingAggregationOperator(OperatorContext operatorContext, List<Type> sourceTypes, List<Type> groupByTypes, List<Integer> groupByChannels, Step step, List<AccumulatorFactory> accumulatorFactories, JoinCompiler joinCompiler) { this.operatorContext = requireNonNull(operatorContext, "operatorContext is null"); this.systemMemoryContext = operatorContext.newLocalSystemMemoryContext(StreamingAggregationOperator.class.getSimpleName()); this.userMemoryContext = operatorContext.localUserMemoryContext(); this.groupByTypes = ImmutableList.copyOf(requireNonNull(groupByTypes, "groupByTypes is null")); this.groupByChannels = Ints.toArray(requireNonNull(groupByChannels, "groupByChannels is null")); this.accumulatorFactories = requireNonNull(accumulatorFactories, "accumulatorFactories is null"); this.step = requireNonNull(step, "step is null"); this.aggregates = setupAggregates(step, accumulatorFactories); this.pageBuilder = new PageBuilder(toTypes(groupByTypes, aggregates)); requireNonNull(joinCompiler, "joinCompiler is null"); requireNonNull(sourceTypes, "sourceTypes is null"); pagesHashStrategy = joinCompiler.compilePagesHashStrategyFactory(sourceTypes, groupByChannels, Optional.empty()) .createPagesHashStrategy( sourceTypes.stream() .map(type -> ImmutableList.<Block>of()) .collect(toImmutableList()), OptionalInt.empty()); }
@Test public void testEmptyStateOutputIsNull() { InternalAggregationFunction aggregationFunction = getInternalAggregationFunction(BIGINT, BIGINT); GroupedAccumulator groupedAccumulator = aggregationFunction.bind(Ints.asList(), Optional.empty()).createGroupedAccumulator(); BlockBuilder blockBuilder = groupedAccumulator.getFinalType().createBlockBuilder(null, 1); groupedAccumulator.evaluateFinal(0, blockBuilder); assertTrue(blockBuilder.isNull(0)); }
@Test(dataProvider = "partitionCount") public void test(int partitionCount) { InternalAggregationFunction function = getFunction(); List<OGCGeometry> geometries = makeGeometries(); Block geometryBlock = makeGeometryBlock(geometries); Block partitionCountBlock = BlockAssertions.createRLEBlock(partitionCount, geometries.size()); Rectangle expectedExtent = new Rectangle(-10, -10, Math.nextUp(10.0), Math.nextUp(10.0)); String expectedValue = getSpatialPartitioning(expectedExtent, geometries, partitionCount); AccumulatorFactory accumulatorFactory = function.bind(Ints.asList(0, 1, 2), Optional.empty()); Page page = new Page(geometryBlock, partitionCountBlock); Accumulator accumulator = accumulatorFactory.createAccumulator(); accumulator.addInput(page); String aggregation = (String) BlockAssertions.getOnlyValue(accumulator.getFinalType(), getFinalBlock(accumulator)); assertEquals(aggregation, expectedValue); GroupedAccumulator groupedAggregation = accumulatorFactory.createGroupedAccumulator(); groupedAggregation.addInput(createGroupByIdBlock(0, page.getPositionCount()), page); String groupValue = (String) getGroupValue(groupedAggregation, 0); assertEquals(groupValue, expectedValue); }
private DistinctingAccumulator( Accumulator accumulator, List<Type> inputTypes, List<Integer> inputs, Optional<Integer> maskChannel, Session session, JoinCompiler joinCompiler) { this.accumulator = requireNonNull(accumulator, "accumulator is null"); this.maskChannel = requireNonNull(maskChannel, "maskChannel is null"); hash = new MarkDistinctHash(session, inputTypes, Ints.toArray(inputs), Optional.empty(), joinCompiler, UpdateMemory.NOOP); }
@Test public void testPageSorterSorted() { List<Type> types = ImmutableList.of(BIGINT, DOUBLE, VARCHAR); List<Integer> sortChannels = Ints.asList(0); List<SortOrder> sortOrders = ImmutableList.of(ASC_NULLS_FIRST); List<Page> inputPages = RowPagesBuilder.rowPagesBuilder(types) .row(-12L, 2.2, "a") .row(-2L, 2.2, "b") .pageBreak() .row(1L, 2.2, "d") .row(2L, 1.1, "c") .build(); List<Page> expectedPages = RowPagesBuilder.rowPagesBuilder(types) .row(-12L, 2.2, "a") .row(-2L, 2.2, "b") .row(1L, 2.2, "d") .row(2L, 1.1, "c") .build(); assertSorted(inputPages, expectedPages, types, sortChannels, sortOrders, 100); }
private static void insertTestData(CassandraSession session, SchemaTableName table, Date date, int rowsCount) { for (Integer rowNumber = 1; rowNumber <= rowsCount; rowNumber++) { Insert insert = QueryBuilder.insertInto(table.getSchemaName(), table.getTableName()) .value("key", "key " + rowNumber.toString()) .value("typeuuid", UUID.fromString(String.format("00000000-0000-0000-0000-%012d", rowNumber))) .value("typeinteger", rowNumber) .value("typelong", rowNumber.longValue() + 1000) .value("typebytes", ByteBuffer.wrap(Ints.toByteArray(rowNumber)).asReadOnlyBuffer()) .value("typetimestamp", date) .value("typeansi", "ansi " + rowNumber) .value("typeboolean", rowNumber % 2 == 0) .value("typedecimal", new BigDecimal(Math.pow(2, rowNumber))) .value("typedouble", Math.pow(4, rowNumber)) .value("typefloat", (float) Math.pow(8, rowNumber)) .value("typeinet", InetAddresses.forString("127.0.0.1")) .value("typevarchar", "varchar " + rowNumber) .value("typevarint", BigInteger.TEN.pow(rowNumber)) .value("typetimeuuid", UUID.fromString(String.format("d2177dd0-eaa2-11de-a572-001b779c76e%d", rowNumber))) .value("typelist", ImmutableList.of("list-value-1" + rowNumber, "list-value-2" + rowNumber)) .value("typemap", ImmutableMap.of(rowNumber, rowNumber + 1L, rowNumber + 2, rowNumber + 3L)) .value("typeset", ImmutableSet.of(false, true)); session.execute(insert); } assertEquals(session.execute("SELECT COUNT(*) FROM " + table).all().get(0).getLong(0), rowsCount); } }
@Override public ListenableFuture<PrestoThriftPageResult> getRows(PrestoThriftId splitId, List<String> columns, long maxBytes, PrestoThriftNullableToken nextToken) { if (rowsPerSplit == 0) { return immediateFuture(new PrestoThriftPageResult(ImmutableList.of(), 0, null)); } int key = Ints.fromByteArray(splitId.getId()); int offset = nextToken.getToken() != null ? Ints.fromByteArray(nextToken.getToken().getId()) : 0; PrestoThriftId newNextToken = offset + 1 < rowsPerSplit ? new PrestoThriftId(Ints.toByteArray(offset + 1)) : null; return immediateFuture(pageResult(key * 10 + offset, newNextToken)); }
@Test public void testPartitionKeyPredicate() { String sql = "SELECT *" + " FROM " + TABLE_ALL_TYPES_PARTITION_KEY + " WHERE key = 'key 7'" + " AND typeuuid = '00000000-0000-0000-0000-000000000007'" + " AND typeinteger = 7" + " AND typelong = 1007" + " AND typebytes = from_hex('" + toRawHexString(ByteBuffer.wrap(toByteArray(7))) + "')" + " AND typetimestamp = TIMESTAMP '1969-12-31 23:04:05'" + " AND typeansi = 'ansi 7'" + " AND typeboolean = false" + " AND typedecimal = 128.0" + " AND typedouble = 16384.0" + " AND typefloat = REAL '2097152.0'" + " AND typeinet = '127.0.0.1'" + " AND typevarchar = 'varchar 7'" + " AND typevarint = '10000000'" + " AND typetimeuuid = 'd2177dd0-eaa2-11de-a572-001b779c76e7'" + " AND typelist = '[\"list-value-17\",\"list-value-27\"]'" + " AND typemap = '{7:8,9:10}'" + " AND typeset = '[false,true]'" + ""; MaterializedResult result = execute(sql); assertEquals(result.getRowCount(), 1); }
public MarkDistinctOperator(OperatorContext operatorContext, List<Type> types, List<Integer> markDistinctChannels, Optional<Integer> hashChannel, JoinCompiler joinCompiler) { this.operatorContext = requireNonNull(operatorContext, "operatorContext is null"); requireNonNull(hashChannel, "hashChannel is null"); requireNonNull(markDistinctChannels, "markDistinctChannels is null"); ImmutableList.Builder<Type> distinctTypes = ImmutableList.builder(); for (int channel : markDistinctChannels) { distinctTypes.add(types.get(channel)); } this.markDistinctHash = new MarkDistinctHash(operatorContext.getSession(), distinctTypes.build(), Ints.toArray(markDistinctChannels), hashChannel, joinCompiler, this::updateMemoryReservation); this.localUserMemoryContext = operatorContext.localUserMemoryContext(); }
@Test public void testConvertVarbinary() throws SQLException { String value = "abc\0xyz"; byte[] bytes = value.getBytes(UTF_8); assertParameter(bytes, Types.VARBINARY, (ps, i) -> ps.setBytes(i, bytes)); assertParameter(bytes, Types.VARBINARY, (ps, i) -> ps.setObject(i, bytes)); for (int type : asList(Types.BINARY, Types.VARBINARY, Types.LONGVARBINARY)) { assertParameter(bytes, Types.VARBINARY, (ps, i) -> ps.setObject(i, bytes, type)); assertParameter(bytes, Types.VARBINARY, (ps, i) -> ps.setObject(i, value, type)); } }
@Override public int compare(int[] left, int[] right) { int minLength = Math.min(left.length, right.length); for (int i = 0; i < minLength; i++) { int result = Ints.compare(left[i], right[i]); if (result != 0) { return result; } } return left.length - right.length; }
public MappedRecordSet(RecordSet delegate, List<Integer> delegateFieldIndex) { this.delegate = requireNonNull(delegate, "delegate is null"); this.delegateFieldIndex = Ints.toArray(requireNonNull(delegateFieldIndex, "delegateFieldIndex is null")); List<Type> types = delegate.getColumnTypes(); this.columnTypes = delegateFieldIndex.stream().map(types::get).collect(toImmutableList()); }