public Slice toSlice() { return Slices.wrappedBuffer(MEMORY_DATA_FRAGMENT_CODEC.toJsonBytes(this)); }
private <T> void writeFile(String type, Path path, JsonCodec<T> codec, T value, boolean overwrite) { try { byte[] json = codec.toJsonBytes(value); if (!overwrite) { if (metadataFileSystem.exists(path)) { throw new PrestoException(HIVE_METASTORE_ERROR, type + " file already exists"); } } metadataFileSystem.mkdirs(path.getParent()); // todo implement safer overwrite code try (OutputStream outputStream = metadataFileSystem.create(path, overwrite)) { outputStream.write(json); } } catch (Exception e) { throw new PrestoException(HIVE_METASTORE_ERROR, "Could not write " + type, e); } }
writer.commit(); PartitionUpdate partitionUpdate = writer.getPartitionUpdate(); partitionUpdates.add(wrappedBuffer(partitionUpdateCodec.toJsonBytes(partitionUpdate))); writer.getVerificationTask() .map(Executors::callable)
throw new PrestoException(HIVE_METASTORE_ERROR, "Partition already exists"); byte[] schemaJson = partitionCodec.toJsonBytes(new PartitionMetadata(table, partitionWithStatistics)); schemaFiles.put(schemaPath, schemaJson);
partitionUpdateJsonCodec.toJsonBytes( new PartitionUpdate( partitionName,
indexColumnNames, thriftPageToList(keys, begin, end)); splits.add(new PrestoThriftSplit(new PrestoThriftId(SPLIT_INFO_CODEC.toJsonBytes(splitInfo)), ImmutableList.of()));
private static PrestoThriftSplitBatch getSplitsSync( PrestoThriftSchemaTableName schemaTableName, int maxSplitCount, PrestoThriftNullableToken nextToken) { int totalParts = DEFAULT_NUMBER_OF_SPLITS; // last sent part int partNumber = nextToken.getToken() == null ? 0 : Ints.fromByteArray(nextToken.getToken().getId()); int numberOfSplits = min(maxSplitCount, totalParts - partNumber); List<PrestoThriftSplit> splits = new ArrayList<>(numberOfSplits); for (int i = 0; i < numberOfSplits; i++) { SplitInfo splitInfo = normalSplit( schemaTableName.getSchemaName(), schemaTableName.getTableName(), partNumber + 1, totalParts); splits.add(new PrestoThriftSplit(new PrestoThriftId(SPLIT_INFO_CODEC.toJsonBytes(splitInfo)), ImmutableList.of())); partNumber++; } PrestoThriftId newNextToken = partNumber < totalParts ? new PrestoThriftId(Ints.toByteArray(partNumber)) : null; return new PrestoThriftSplitBatch(splits, newNextToken); }
private static void assertProperties(Map<String, String> properties, SessionMatchSpec... spec) throws IOException { try (TempFile tempFile = new TempFile()) { Path configurationFile = tempFile.path(); Files.write(configurationFile, CODEC.toJsonBytes(Arrays.asList(spec))); SessionPropertyConfigurationManager manager = new FileSessionPropertyManager(new FileSessionPropertyManagerConfig().setConfigFile(configurationFile.toFile())); assertEquals(manager.getSystemSessionProperties(CONTEXT), properties); } } }
outputBuffers.get(), totalPartitions); byte[] taskUpdateRequestJson = taskUpdateRequestCodec.toJsonBytes(updateRequest); if (fragment.isPresent()) { stats.updateWithPlanBytes(taskUpdateRequestJson.length);
private JsonBodyGenerator(JsonCodec<T> jsonCodec, T instance) { super(jsonCodec.toJsonBytes(instance)); } }
@Test public void testSerialization() throws Exception { JsonCodec<Entry> codec = jsonCodec(Entry.class); Entry expected = entryOf("fruit", "apple", 123, 456); Entry actual = codec.fromJson(codec.toJsonBytes(expected)); assertEquals(actual, expected); }
public static void validatePersonMapJsonCodec(JsonCodec<Map<String, ImmutablePerson>> jsonCodec) { ImmutableMap<String, ImmutablePerson> expected = ImmutableMap.<String, ImmutablePerson>builder() .put("dain", new ImmutablePerson("dain", true)) .put("martin", new ImmutablePerson("martin", true)) .put("mark", new ImmutablePerson("mark", true)) .build(); String json = jsonCodec.toJson(expected); assertEquals(jsonCodec.fromJson(json), expected); byte[] bytes = jsonCodec.toJsonBytes(expected); assertEquals(jsonCodec.fromJson(bytes), expected); }
public static void validatePersonMapJsonCodec(JsonCodec<Map<String, ImmutablePerson>> jsonCodec) { ImmutableMap<String, ImmutablePerson> expected = ImmutableMap.<String, ImmutablePerson>builder() .put("dain", new ImmutablePerson("dain", true)) .put("martin", new ImmutablePerson("martin", true)) .put("mark", new ImmutablePerson("mark", true)) .build(); String json = jsonCodec.toJson(expected); assertEquals(jsonCodec.fromJson(json), expected); byte[] bytes = jsonCodec.toJsonBytes(expected); assertEquals(jsonCodec.fromJson(bytes), expected); }
public static void validatePersonJsonCodec(JsonCodec<ImmutablePerson> jsonCodec) { ImmutablePerson expected = new ImmutablePerson("dain", true); String json = jsonCodec.toJson(expected); assertEquals(jsonCodec.fromJson(json), expected); byte[] bytes = jsonCodec.toJsonBytes(expected); assertEquals(jsonCodec.fromJson(bytes), expected); }
public static void validatePersonJsonCodec(JsonCodec<ImmutablePerson> jsonCodec) { ImmutablePerson expected = new ImmutablePerson("dain", true); String json = jsonCodec.toJson(expected); assertEquals(jsonCodec.fromJson(json), expected); byte[] bytes = jsonCodec.toJsonBytes(expected); assertEquals(jsonCodec.fromJson(bytes), expected); }
public static void validatePersonListJsonCodec(JsonCodec<List<ImmutablePerson>> jsonCodec) { ImmutableList<ImmutablePerson> expected = ImmutableList.of( new ImmutablePerson("dain", true), new ImmutablePerson("martin", true), new ImmutablePerson("mark", true)); String json = jsonCodec.toJson(expected); assertEquals(jsonCodec.fromJson(json), expected); byte[] bytes = jsonCodec.toJsonBytes(expected); assertEquals(jsonCodec.fromJson(bytes), expected); }
public static void validatePersonListJsonCodec(JsonCodec<List<ImmutablePerson>> jsonCodec) { ImmutableList<ImmutablePerson> expected = ImmutableList.of( new ImmutablePerson("dain", true), new ImmutablePerson("martin", true), new ImmutablePerson("mark", true)); String json = jsonCodec.toJson(expected); assertEquals(jsonCodec.fromJson(json), expected); byte[] bytes = jsonCodec.toJsonBytes(expected); assertEquals(jsonCodec.fromJson(bytes), expected); }
public static void validatePersonMapJsonCodec(JsonCodec<Map<String, Person>> jsonCodec) { ImmutableMap<String, Person> expected = ImmutableMap.<String, Person>builder() .put("dain", new Person().setName("dain").setRocks(true)) .put("martin", new Person().setName("martin").setRocks(true)) .put("mark", new Person().setName("mark").setRocks(true)) .build(); String json = jsonCodec.toJson(expected); assertEquals(jsonCodec.fromJson(json), expected); byte[] bytes = jsonCodec.toJsonBytes(expected); assertEquals(jsonCodec.fromJson(bytes), expected); }
public static void validatePersonListJsonCodec(JsonCodec<List<Person>> jsonCodec) { ImmutableList<Person> expected = ImmutableList.of( new Person().setName("dain").setRocks(true), new Person().setName("martin").setRocks(true), new Person().setName("mark").setRocks(true)); String json = jsonCodec.toJson(expected); assertEquals(jsonCodec.fromJson(json), expected); byte[] bytes = jsonCodec.toJsonBytes(expected); assertEquals(jsonCodec.fromJson(bytes), expected); }
public static void validatePersonListJsonCodec(JsonCodec<List<Person>> jsonCodec) { ImmutableList<Person> expected = ImmutableList.of( new Person().setName("dain").setRocks(true), new Person().setName("martin").setRocks(true), new Person().setName("mark").setRocks(true)); String json = jsonCodec.toJson(expected); assertEquals(jsonCodec.fromJson(json), expected); byte[] bytes = jsonCodec.toJsonBytes(expected); assertEquals(jsonCodec.fromJson(bytes), expected); }