Search in sources :

Example 1 with SortingProperty

use of io.prestosql.spi.connector.SortingProperty in project hetu-core by openlookeng.

the class TestLocalProperties method testJsonSerialization.

@Test
public void testJsonSerialization() throws Exception {
    ObjectMapper mapper = new ObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(ColumnHandle.class, new JsonDeserializer<ColumnHandle>() {

        @Override
        public ColumnHandle deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
            return new ObjectMapperProvider().get().readValue(jsonParser, TestingColumnHandle.class);
        }
    }));
    TestingColumnHandle columnHandle = new TestingColumnHandle("a");
    LocalProperty<ColumnHandle> property1 = new ConstantProperty<>(columnHandle);
    assertEquals(property1, mapper.readValue(mapper.writeValueAsString(property1), new TypeReference<LocalProperty<ColumnHandle>>() {
    }));
    LocalProperty<ColumnHandle> property2 = new SortingProperty<>(columnHandle, SortOrder.ASC_NULLS_FIRST);
    assertEquals(property2, mapper.readValue(mapper.writeValueAsString(property2), new TypeReference<LocalProperty<ColumnHandle>>() {
    }));
    LocalProperty<ColumnHandle> property3 = new GroupingProperty<>(ImmutableList.of(columnHandle));
    assertEquals(property3, mapper.readValue(mapper.writeValueAsString(property3), new TypeReference<LocalProperty<ColumnHandle>>() {
    }));
}
Also used : TestingColumnHandle(io.prestosql.testing.TestingMetadata.TestingColumnHandle) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) ConstantProperty(io.prestosql.spi.connector.ConstantProperty) GroupingProperty(io.prestosql.spi.connector.GroupingProperty) SortingProperty(io.prestosql.spi.connector.SortingProperty) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) TestingColumnHandle(io.prestosql.testing.TestingMetadata.TestingColumnHandle) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) JsonParser(com.fasterxml.jackson.core.JsonParser) Test(org.testng.annotations.Test)

Example 2 with SortingProperty

use of io.prestosql.spi.connector.SortingProperty in project hetu-core by openlookeng.

the class TpchMetadata method getTableProperties.

@Override
public ConnectorTableProperties getTableProperties(ConnectorSession session, ConnectorTableHandle table) {
    TpchTableHandle tableHandle = (TpchTableHandle) table;
    Optional<ConnectorTablePartitioning> tablePartitioning = Optional.empty();
    Optional<Set<ColumnHandle>> partitioningColumns = Optional.empty();
    List<LocalProperty<ColumnHandle>> localProperties = ImmutableList.of();
    Map<String, ColumnHandle> columns = getColumnHandles(session, tableHandle);
    if (partitioningEnabled && tableHandle.getTableName().equals(TpchTable.ORDERS.getTableName())) {
        ColumnHandle orderKeyColumn = columns.get(columnNaming.getName(OrderColumn.ORDER_KEY));
        tablePartitioning = Optional.of(new ConnectorTablePartitioning(new TpchPartitioningHandle(TpchTable.ORDERS.getTableName(), calculateTotalRows(OrderGenerator.SCALE_BASE, tableHandle.getScaleFactor())), ImmutableList.of(orderKeyColumn)));
        partitioningColumns = Optional.of(ImmutableSet.of(orderKeyColumn));
        localProperties = ImmutableList.of(new SortingProperty<>(orderKeyColumn, SortOrder.ASC_NULLS_FIRST));
    } else if (partitioningEnabled && tableHandle.getTableName().equals(TpchTable.LINE_ITEM.getTableName())) {
        ColumnHandle orderKeyColumn = columns.get(columnNaming.getName(LineItemColumn.ORDER_KEY));
        tablePartitioning = Optional.of(new ConnectorTablePartitioning(new TpchPartitioningHandle(TpchTable.ORDERS.getTableName(), calculateTotalRows(OrderGenerator.SCALE_BASE, tableHandle.getScaleFactor())), ImmutableList.of(orderKeyColumn)));
        partitioningColumns = Optional.of(ImmutableSet.of(orderKeyColumn));
        localProperties = ImmutableList.of(new SortingProperty<>(orderKeyColumn, SortOrder.ASC_NULLS_FIRST), new SortingProperty<>(columns.get(columnNaming.getName(LineItemColumn.LINE_NUMBER)), SortOrder.ASC_NULLS_FIRST));
    }
    return new ConnectorTableProperties(tableHandle.getConstraint(), tablePartitioning, partitioningColumns, Optional.empty(), localProperties);
}
Also used : ColumnHandle(io.prestosql.spi.connector.ColumnHandle) Collectors.toSet(java.util.stream.Collectors.toSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ConnectorTablePartitioning(io.prestosql.spi.connector.ConnectorTablePartitioning) SortingProperty(io.prestosql.spi.connector.SortingProperty) LocalProperty(io.prestosql.spi.connector.LocalProperty) ConnectorTableProperties(io.prestosql.spi.connector.ConnectorTableProperties)

Aggregations

ColumnHandle (io.prestosql.spi.connector.ColumnHandle)2 SortingProperty (io.prestosql.spi.connector.SortingProperty)2 JsonParser (com.fasterxml.jackson.core.JsonParser)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)1 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)1 ConnectorTablePartitioning (io.prestosql.spi.connector.ConnectorTablePartitioning)1 ConnectorTableProperties (io.prestosql.spi.connector.ConnectorTableProperties)1 ConstantProperty (io.prestosql.spi.connector.ConstantProperty)1 GroupingProperty (io.prestosql.spi.connector.GroupingProperty)1 LocalProperty (io.prestosql.spi.connector.LocalProperty)1 TestingColumnHandle (io.prestosql.testing.TestingMetadata.TestingColumnHandle)1 Set (java.util.Set)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 Test (org.testng.annotations.Test)1