public Slice getLengthData() { checkArgument(columnClosed, "Column is open"); return lengthOutput.slice(); }
@Override public Block build() { if (currentEntrySize > 0) { throw new IllegalStateException("Current entry must be closed before the block can be built"); } return new VariableWidthBlock(0, positions, sliceOutput.slice(), offsets, hasNullValue ? valueIsNull : null); }
@Override public void serialize(Block block, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { SliceOutput output = new DynamicSliceOutput(64); writeBlock(blockEncodingSerde, output, block); String encoded = Base64.getEncoder().encodeToString(output.slice().getBytes()); jsonGenerator.writeString(encoded); } }
private static Slice internalCastFromLong(long value, int estimatedSize) { try { SliceOutput output = new DynamicSliceOutput(estimatedSize); try (JsonGenerator jsonGenerator = createJsonGenerator(JSON_FACTORY, output)) { jsonGenerator.writeNumber(value); } return output.slice(); } catch (IOException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to %s", value, JSON)); } }
private static Slice decimalToJson(BigDecimal bigDecimal) { try { SliceOutput dynamicSliceOutput = new DynamicSliceOutput(32); try (JsonGenerator jsonGenerator = createJsonGenerator(JSON_FACTORY, dynamicSliceOutput)) { jsonGenerator.writeNumber(bigDecimal); } return dynamicSliceOutput.slice(); } catch (IOException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%f' to %s", bigDecimal, StandardTypes.JSON)); } }
@Override public Block getRegion(int positionOffset, int length) { int positionCount = getPositionCount(); checkValidRegion(positionCount, positionOffset, length); Slice newSlice = sliceOutput.slice().slice(positionOffset * fixedSize, length * fixedSize); Slice newValueIsNull = null; if (hasNullValue) { newValueIsNull = valueIsNull.slice().slice(positionOffset, length); } return new FixedWidthBlock(fixedSize, length, newSlice, newValueIsNull); }
@Override public Block getRegion(int positionOffset, int length) { int positionCount = getPositionCount(); checkValidRegion(positionCount, positionOffset, length); return new VariableWidthBlock(positionOffset, length, sliceOutput.slice(), offsets, hasNullValue ? valueIsNull : null); }
@ScalarOperator(CAST) @SqlType(JSON) public static Slice castFromReal(@SqlType(REAL) long value) { try { SliceOutput output = new DynamicSliceOutput(32); try (JsonGenerator jsonGenerator = createJsonGenerator(JSON_FACTORY, output)) { jsonGenerator.writeNumber(intBitsToFloat((int) value)); } return output.slice(); } catch (IOException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to %s", value, JSON)); } }
@ScalarOperator(CAST) @SqlType(JSON) public static Slice castFromDouble(@SqlType(DOUBLE) double value) { try { SliceOutput output = new DynamicSliceOutput(32); try (JsonGenerator jsonGenerator = createJsonGenerator(JSON_FACTORY, output)) { jsonGenerator.writeNumber(value); } return output.slice(); } catch (IOException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to %s", value, JSON)); } }
@Test public void testNoStartSync() throws Exception { SliceOutput output = new DynamicSliceOutput(10 * 1024); List<Segment> segments = ImmutableList.of( writeSegment(output, ImmutableList.of(ImmutableList.of(0, 2, 3, 4), ImmutableList.of(10, 12, 13))), writeSegment(output, ImmutableList.of(ImmutableList.of(20, 22), ImmutableList.of(30, 33), ImmutableList.of(40, 44))), writeSegment(output, ImmutableList.of(ImmutableList.of(100, 101, 102)))); assertFileSegments(output.slice(), segments); }
@Test public void testStartSync() throws Exception { SliceOutput output = new DynamicSliceOutput(10 * 1024); List<Segment> segments = ImmutableList.of( writeSegment(output, ImmutableList.of()), writeSegment(output, ImmutableList.of(ImmutableList.of(0, 2, 3, 4), ImmutableList.of(10, 12, 13))), writeSegment(output, ImmutableList.of(ImmutableList.of(20, 22), ImmutableList.of(30, 33), ImmutableList.of(40, 44))), writeSegment(output, ImmutableList.of(ImmutableList.of(100, 101, 102)))); assertFileSegments(output.slice(), segments); }
@Override public void serialize(Block block, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { SliceOutput output = new DynamicSliceOutput(64); blockEncodingSerde.writeBlock(output, block); String encoded = Base64.getEncoder().encodeToString(output.slice().getBytes()); jsonGenerator.writeString(encoded); } }
@ScalarOperator(CAST) @SqlType(JSON) public static Slice castFromDate(ConnectorSession session, @SqlType(DATE) long value) { try { SliceOutput output = new DynamicSliceOutput(12); try (JsonGenerator jsonGenerator = createJsonGenerator(JSON_FACTORY, output)) { jsonGenerator.writeString(printDate((int) value)); } return output.slice(); } catch (IOException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to %s", value, JSON)); } }
private Slice blockToSlice(Block block) { // This function is strictly for testing use only SliceOutput sliceOutput = new DynamicSliceOutput(1000); BlockSerdeUtil.writeBlock(blockEncodingSerde, sliceOutput, block); return sliceOutput.slice(); }
private Slice blockToSlice(Block block) { // This function is strictly for testing use only SliceOutput sliceOutput = new DynamicSliceOutput(1000); BlockSerdeUtil.writeBlock(blockEncodingSerde, sliceOutput, block); return sliceOutput.slice(); }
@ScalarOperator(CAST) @SqlType(JSON) public static Slice castFromTimestamp(ConnectorSession session, @SqlType(TIMESTAMP) long value) { try { SliceOutput output = new DynamicSliceOutput(25); try (JsonGenerator jsonGenerator = createJsonGenerator(JSON_FACTORY, output)) { jsonGenerator.writeString(printTimestampWithoutTimeZone(session.getTimeZoneKey(), value)); } return output.slice(); } catch (IOException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to %s", value, JSON)); } }
@ScalarOperator(CAST) @SqlType(JSON) public static Slice castFromBoolean(@SqlType(BOOLEAN) boolean value) { try { SliceOutput output = new DynamicSliceOutput(5); try (JsonGenerator jsonGenerator = createJsonGenerator(JSON_FACTORY, output)) { jsonGenerator.writeBoolean(value); } return output.slice(); } catch (IOException e) { throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast '%s' to %s", value, JSON)); } }
@Override public byte[] getSerializedData() { // Serialization format is (<key:int><min:double><max:double>)* SliceOutput output = Slices.allocate((SizeOf.SIZE_OF_INT + 2 * SizeOf.SIZE_OF_DOUBLE) * mins.size()).getOutput(); for (int key : mins.keySet()) { output.appendInt(key); output.appendDouble(mins.get(key)); output.appendDouble(maxs.get(key)); } return output.slice().getBytes(); }
@Override public void serialize(DigestAndPercentileState state, BlockBuilder out) { if (state.getDigest() == null) { out.appendNull(); } else { Slice serialized = state.getDigest().serialize(); SliceOutput output = Slices.allocate(SIZE_OF_DOUBLE + SIZE_OF_INT + serialized.length()).getOutput(); output.appendDouble(state.getPercentile()); output.appendInt(serialized.length()); output.appendBytes(serialized); VARBINARY.writeSlice(out, output.slice()); } }