Java Code Examples for io.airlift.json.JsonCodec#toJson()
The following examples show how to use
io.airlift.json.JsonCodec#toJson() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestHiveColumnHandle.java From presto with Apache License 2.0 | 6 votes |
private void testRoundTrip(HiveColumnHandle expected) { ObjectMapperProvider objectMapperProvider = new ObjectMapperProvider(); objectMapperProvider.setJsonDeserializers(ImmutableMap.of(Type.class, new HiveModule.TypeDeserializer(new InternalTypeManager(createTestMetadataManager())))); JsonCodec<HiveColumnHandle> codec = new JsonCodecFactory(objectMapperProvider).jsonCodec(HiveColumnHandle.class); String json = codec.toJson(expected); HiveColumnHandle actual = codec.fromJson(json); assertEquals(actual.getBaseColumnName(), expected.getBaseColumnName()); assertEquals(actual.getBaseHiveColumnIndex(), expected.getBaseHiveColumnIndex()); assertEquals(actual.getBaseType(), expected.getBaseType()); assertEquals(actual.getBaseHiveType(), expected.getBaseHiveType()); assertEquals(actual.getName(), expected.getName()); assertEquals(actual.getType(), expected.getType()); assertEquals(actual.getHiveType(), expected.getHiveType()); assertEquals(actual.getHiveColumnProjectionInfo(), expected.getHiveColumnProjectionInfo()); assertEquals(actual.isPartitionKey(), expected.isPartitionKey()); }
Example 2
Source File: TestSignature.java From presto with Apache License 2.0 | 6 votes |
@Test public void testSerializationRoundTrip() { ObjectMapperProvider objectMapperProvider = new ObjectMapperProvider(); objectMapperProvider.setJsonDeserializers(ImmutableMap.of( Type.class, new TypeDeserializer(createTestMetadataManager()), TypeSignature.class, new TypeSignatureDeserializer())); JsonCodec<Signature> codec = new JsonCodecFactory(objectMapperProvider, true).jsonCodec(Signature.class); Signature expected = new Signature( "function", BIGINT.getTypeSignature(), ImmutableList.of(BOOLEAN.getTypeSignature(), DOUBLE.getTypeSignature(), VARCHAR.getTypeSignature())); String json = codec.toJson(expected); Signature actual = codec.fromJson(json); assertEquals(actual.getName(), expected.getName()); assertEquals(actual.getReturnType(), expected.getReturnType()); assertEquals(actual.getArgumentTypes(), expected.getArgumentTypes()); }
Example 3
Source File: TestDriverStats.java From presto with Apache License 2.0 | 5 votes |
@Test public void testJson() { JsonCodec<DriverStats> codec = JsonCodec.jsonCodec(DriverStats.class); String json = codec.toJson(EXPECTED); DriverStats actual = codec.fromJson(json); assertExpectedDriverStats(actual); }
Example 4
Source File: TestPinotTableHandle.java From presto with Apache License 2.0 | 5 votes |
@Test public void testJsonRoundTrip() { JsonCodec<PinotTableHandle> codec = jsonCodec(PinotTableHandle.class); String json = codec.toJson(tableHandle); PinotTableHandle copy = codec.fromJson(json); assertEquals(copy, tableHandle); }
Example 5
Source File: TestLocalFileSplit.java From presto with Apache License 2.0 | 5 votes |
@Test public void testJsonRoundTrip() { JsonCodec<LocalFileSplit> codec = jsonCodec(LocalFileSplit.class); String json = codec.toJson(split); LocalFileSplit copy = codec.fromJson(json); assertEquals(copy.getAddress(), split.getAddress()); assertEquals(copy.getAddresses(), ImmutableList.of(address)); assertEquals(copy.isRemotelyAccessible(), false); }
Example 6
Source File: TestQueryProgressStats.java From presto with Apache License 2.0 | 5 votes |
@Test public void testJson() { QueryProgressStats expected = new QueryProgressStats( 123456, 1111, 22222, 3333, 100000, 34230492, 1000, 100000, false, OptionalDouble.of(33.33)); JsonCodec<QueryProgressStats> codec = JsonCodec.jsonCodec(QueryProgressStats.class); String json = codec.toJson(expected); QueryProgressStats actual = codec.fromJson(json); assertEquals(actual.getElapsedTimeMillis(), 123456); assertEquals(actual.getQueuedTimeMillis(), 1111); assertEquals(actual.getCpuTimeMillis(), 22222); assertEquals(actual.getScheduledTimeMillis(), 3333); assertEquals(actual.getCurrentMemoryBytes(), 100000); assertEquals(actual.getPeakMemoryBytes(), 34230492); assertEquals(actual.getInputRows(), 1000); assertEquals(actual.getInputBytes(), 100000); assertFalse(actual.isBlocked()); assertEquals(actual.getProgressPercentage(), OptionalDouble.of(33.33)); }
Example 7
Source File: TestQueryStats.java From presto with Apache License 2.0 | 5 votes |
@Test public void testJson() { JsonCodec<QueryStats> codec = JsonCodec.jsonCodec(QueryStats.class); String json = codec.toJson(EXPECTED); QueryStats actual = codec.fromJson(json); assertExpectedQueryStats(actual); }
Example 8
Source File: TestStageStats.java From presto with Apache License 2.0 | 5 votes |
@Test public void testJson() { JsonCodec<StageStats> codec = JsonCodec.jsonCodec(StageStats.class); String json = codec.toJson(EXPECTED); StageStats actual = codec.fromJson(json); assertExpectedStageStats(actual); }
Example 9
Source File: TestPrometheusTableHandle.java From presto with Apache License 2.0 | 5 votes |
@Test public void testJsonRoundTrip() { JsonCodec<PrometheusTableHandle> codec = jsonCodec(PrometheusTableHandle.class); String json = codec.toJson(tableHandle); PrometheusTableHandle copy = codec.fromJson(json); assertEquals(copy, tableHandle); }
Example 10
Source File: TestTaskStats.java From presto with Apache License 2.0 | 5 votes |
@Test public void testJson() { JsonCodec<TaskStats> codec = JsonCodec.jsonCodec(TaskStats.class); String json = codec.toJson(EXPECTED); TaskStats actual = codec.fromJson(json); assertExpectedTaskStats(actual); }
Example 11
Source File: TestOperatorStats.java From presto with Apache License 2.0 | 5 votes |
@Test public void testJson() { JsonCodec<OperatorStats> codec = JsonCodec.jsonCodec(OperatorStats.class); String json = codec.toJson(EXPECTED); OperatorStats actual = codec.fromJson(json); assertExpectedOperatorStats(actual); }
Example 12
Source File: TestPipelineStats.java From presto with Apache License 2.0 | 5 votes |
@Test public void testJson() { JsonCodec<PipelineStats> codec = JsonCodec.jsonCodec(PipelineStats.class); String json = codec.toJson(EXPECTED); PipelineStats actual = codec.fromJson(json); assertExpectedPipelineStats(actual); }
Example 13
Source File: TestJdbcSplit.java From presto with Apache License 2.0 | 5 votes |
@Test public void testJsonRoundTrip() { JsonCodec<JdbcSplit> codec = jsonCodec(JdbcSplit.class); String json = codec.toJson(split); JdbcSplit copy = codec.fromJson(json); assertEquals(copy.getAdditionalPredicate(), split.getAdditionalPredicate()); assertEquals(copy.getAddresses(), ImmutableList.of()); assertEquals(copy.isRemotelyAccessible(), true); }
Example 14
Source File: TestExampleSplit.java From presto with Apache License 2.0 | 5 votes |
@Test public void testJsonRoundTrip() { JsonCodec<ExampleSplit> codec = jsonCodec(ExampleSplit.class); String json = codec.toJson(split); ExampleSplit copy = codec.fromJson(json); assertEquals(copy.getUri(), split.getUri()); assertEquals(copy.getAddresses(), ImmutableList.of(HostAddress.fromString("127.0.0.1"))); assertEquals(copy.isRemotelyAccessible(), true); }
Example 15
Source File: TestExampleTableHandle.java From presto with Apache License 2.0 | 5 votes |
@Test public void testJsonRoundTrip() { JsonCodec<ExampleTableHandle> codec = jsonCodec(ExampleTableHandle.class); String json = codec.toJson(tableHandle); ExampleTableHandle copy = codec.fromJson(json); assertEquals(copy, tableHandle); }
Example 16
Source File: TestPrometheusSplit.java From presto with Apache License 2.0 | 5 votes |
@Test public void testJsonRoundTrip() { JsonCodec<PrometheusSplit> codec = jsonCodec(PrometheusSplit.class); String json = codec.toJson(split); PrometheusSplit copy = codec.fromJson(json); assertEquals(copy.getUri(), split.getUri()); assertEquals(copy.getAddresses(), ImmutableList.of(HostAddress.fromString("127.0.0.1"))); assertEquals(copy.isRemotelyAccessible(), true); }
Example 17
Source File: MetadataUtil.java From presto with Apache License 2.0 | 4 votes |
public static <T> void assertJsonRoundTrip(JsonCodec<T> codec, T object) { String json = codec.toJson(object); T copy = codec.fromJson(json); assertEquals(copy, object); }
Example 18
Source File: TestHiveSplit.java From presto with Apache License 2.0 | 4 votes |
@Test public void testJsonRoundTrip() { ObjectMapperProvider objectMapperProvider = new ObjectMapperProvider(); objectMapperProvider.setJsonDeserializers(ImmutableMap.of(Type.class, new HiveModule.TypeDeserializer(new TestingTypeManager()))); JsonCodec<HiveSplit> codec = new JsonCodecFactory(objectMapperProvider).jsonCodec(HiveSplit.class); Properties schema = new Properties(); schema.setProperty("foo", "bar"); schema.setProperty("bar", "baz"); ImmutableList<HivePartitionKey> partitionKeys = ImmutableList.of(new HivePartitionKey("a", "apple"), new HivePartitionKey("b", "42")); ImmutableList<HostAddress> addresses = ImmutableList.of(HostAddress.fromParts("127.0.0.1", 44), HostAddress.fromParts("127.0.0.1", 45)); AcidInfo.Builder acidInfoBuilder = AcidInfo.builder(new Path("file:///data/fullacid")); acidInfoBuilder.addDeleteDelta(new Path("file:///data/fullacid/delete_delta_0000004_0000004_0000"), 4L, 4L, 0); acidInfoBuilder.addDeleteDelta(new Path("file:///data/fullacid/delete_delta_0000007_0000007_0000"), 7L, 7L, 0); AcidInfo acidInfo = acidInfoBuilder.build().get(); HiveSplit expected = new HiveSplit( "db", "table", "partitionId", "path", 42, 87, 88, Instant.now().toEpochMilli(), schema, partitionKeys, addresses, OptionalInt.empty(), true, TableToPartitionMapping.mapColumnsByIndex(ImmutableMap.of(1, new HiveTypeName("string"))), Optional.of(new HiveSplit.BucketConversion( BUCKETING_V1, 32, 16, ImmutableList.of(createBaseColumn("col", 5, HIVE_LONG, BIGINT, ColumnType.REGULAR, Optional.of("comment"))))), false, Optional.of(acidInfo)); String json = codec.toJson(expected); HiveSplit actual = codec.fromJson(json); assertEquals(actual.getDatabase(), expected.getDatabase()); assertEquals(actual.getTable(), expected.getTable()); assertEquals(actual.getPartitionName(), expected.getPartitionName()); assertEquals(actual.getPath(), expected.getPath()); assertEquals(actual.getStart(), expected.getStart()); assertEquals(actual.getLength(), expected.getLength()); assertEquals(actual.getFileSize(), expected.getFileSize()); assertEquals(actual.getSchema(), expected.getSchema()); assertEquals(actual.getPartitionKeys(), expected.getPartitionKeys()); assertEquals(actual.getAddresses(), expected.getAddresses()); assertEquals(actual.getTableToPartitionMapping().getPartitionColumnCoercions(), expected.getTableToPartitionMapping().getPartitionColumnCoercions()); assertEquals(actual.getTableToPartitionMapping().getTableToPartitionColumns(), expected.getTableToPartitionMapping().getTableToPartitionColumns()); assertEquals(actual.getBucketConversion(), expected.getBucketConversion()); assertEquals(actual.isForceLocalScheduling(), expected.isForceLocalScheduling()); assertEquals(actual.isS3SelectPushdownEnabled(), expected.isS3SelectPushdownEnabled()); assertEquals(actual.getAcidInfo().get(), expected.getAcidInfo().get()); }