Search in sources :

Example 21 with CatalogPartitionSpec

use of org.apache.flink.table.catalog.CatalogPartitionSpec in project flink by apache.

the class TestManagedSinkCommittableSerializer method serialize.

@Override
public byte[] serialize(TestManagedCommittable committable) throws IOException {
    final DataOutputSerializer out = new DataOutputSerializer(64);
    out.writeInt(committable.getToAdd().size());
    for (Map.Entry<CatalogPartitionSpec, List<RowData>> entry : committable.getToAdd().entrySet()) {
        serializePartitionSpec(out, entry.getKey());
        serializeRowDataElements(out, entry.getValue());
    }
    out.writeInt(committable.getToDelete().size());
    for (Map.Entry<CatalogPartitionSpec, Set<Path>> entry : committable.getToDelete().entrySet()) {
        serializePartitionSpec(out, entry.getKey());
        serializePaths(out, entry.getValue());
    }
    final byte[] result = out.getCopyOfBuffer();
    out.clear();
    return result;
}
Also used : DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CatalogPartitionSpec(org.apache.flink.table.catalog.CatalogPartitionSpec)

Example 22 with CatalogPartitionSpec

use of org.apache.flink.table.catalog.CatalogPartitionSpec in project flink by apache.

the class TestManagedSinkWriter method write.

@Override
public void write(RowData element, Context context) throws IOException, InterruptedException {
    assert element.getArity() == 3;
    String partition = element.getString(0).toString();
    Path filePath = new Path(element.getString(1).toString());
    RowData rowData = GenericRowData.of(element.getString(2));
    CatalogPartitionSpec currentPartitionSpec = processedPartitions.getOrDefault(partition, new CatalogPartitionSpec(PartitionPathUtils.extractPartitionSpecFromPath(filePath)));
    processedPartitions.put(partition, currentPartitionSpec);
    List<RowData> elements = stagingElements.getOrDefault(currentPartitionSpec, new ArrayList<>());
    elements.add(rowData);
    stagingElements.put(currentPartitionSpec, elements);
    Set<Path> old = toDelete.getOrDefault(currentPartitionSpec, new HashSet<>());
    old.add(filePath);
    toDelete.put(currentPartitionSpec, old);
}
Also used : Path(org.apache.flink.core.fs.Path) RowData(org.apache.flink.table.data.RowData) GenericRowData(org.apache.flink.table.data.GenericRowData) CatalogPartitionSpec(org.apache.flink.table.catalog.CatalogPartitionSpec)

Example 23 with CatalogPartitionSpec

use of org.apache.flink.table.catalog.CatalogPartitionSpec in project flink by apache.

the class TestManagedTableFactory method resolveCompactFileBasePath.

private static Optional<String> resolveCompactFileBasePath(ObjectIdentifier tableIdentifier) {
    AtomicReference<Map<CatalogPartitionSpec, List<Path>>> reference = MANAGED_TABLE_FILE_ENTRIES.get(tableIdentifier);
    if (reference != null) {
        Map<CatalogPartitionSpec, List<Path>> managedTableFileEntries = reference.get();
        for (Map.Entry<CatalogPartitionSpec, List<Path>> entry : managedTableFileEntries.entrySet()) {
            List<Path> partitionFiles = entry.getValue();
            if (partitionFiles.size() > 0) {
                Path file = partitionFiles.get(0);
                LinkedHashMap<String, String> partitionSpec = PartitionPathUtils.extractPartitionSpecFromPath(file);
                if (partitionSpec.isEmpty()) {
                    return Optional.of(file.getParent().getPath());
                } else {
                    String tableName = tableIdentifier.asSummaryString();
                    int index = file.getPath().indexOf(tableName);
                    if (index != -1) {
                        return Optional.of(file.getPath().substring(0, index + tableName.length()));
                    }
                }
            }
        }
    }
    return Optional.empty();
}
Also used : Path(org.apache.flink.core.fs.Path) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CatalogPartitionSpec(org.apache.flink.table.catalog.CatalogPartitionSpec)

Example 24 with CatalogPartitionSpec

use of org.apache.flink.table.catalog.CatalogPartitionSpec in project flink by apache.

the class CompactManagedTableITCase method testCompactSinglePartitionedTable.

@Test
public void testCompactSinglePartitionedTable() throws Exception {
    String sql = "CREATE TABLE MyTable (\n" + "  id BIGINT,\n" + "  content STRING,\n" + "  season STRING\n" + ") PARTITIONED BY (season)";
    prepare(sql, Arrays.asList(of("season", "'spring'"), of("season", "'summer'")));
    Set<CatalogPartitionSpec> resolvedPartitionSpecsHaveBeenOrToBeCompacted = new HashSet<>();
    // test compact one partition
    CatalogPartitionSpec unresolvedPartitionSpec = new CatalogPartitionSpec(of("season", "'summer'"));
    resolvedPartitionSpecsHaveBeenOrToBeCompacted.add(new CatalogPartitionSpec(of("season", "summer")));
    executeAndCheck(unresolvedPartitionSpec, resolvedPartitionSpecsHaveBeenOrToBeCompacted);
    // test compact the whole table
    unresolvedPartitionSpec = new CatalogPartitionSpec(Collections.emptyMap());
    resolvedPartitionSpecsHaveBeenOrToBeCompacted.add(new CatalogPartitionSpec(of("season", "spring")));
    executeAndCheck(unresolvedPartitionSpec, resolvedPartitionSpecsHaveBeenOrToBeCompacted);
}
Also used : CatalogPartitionSpec(org.apache.flink.table.catalog.CatalogPartitionSpec) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 25 with CatalogPartitionSpec

use of org.apache.flink.table.catalog.CatalogPartitionSpec in project flink by apache.

the class CompactManagedTableITCase method testCompactNonPartitionedTable.

@Test
public void testCompactNonPartitionedTable() throws Exception {
    String sql = "CREATE TABLE MyTable (id BIGINT, content STRING)";
    prepare(sql, Collections.emptyList());
    // test compact table
    CatalogPartitionSpec unresolvedDummySpec = new CatalogPartitionSpec(Collections.emptyMap());
    Set<CatalogPartitionSpec> resolvedPartitionSpecsHaveBeenOrToBeCompacted = Collections.singleton(unresolvedDummySpec);
    executeAndCheck(unresolvedDummySpec, resolvedPartitionSpecsHaveBeenOrToBeCompacted);
}
Also used : CatalogPartitionSpec(org.apache.flink.table.catalog.CatalogPartitionSpec) Test(org.junit.Test)

Aggregations

CatalogPartitionSpec (org.apache.flink.table.catalog.CatalogPartitionSpec)32 HashMap (java.util.HashMap)20 LinkedHashMap (java.util.LinkedHashMap)15 ArrayList (java.util.ArrayList)11 Map (java.util.Map)11 ObjectPath (org.apache.flink.table.catalog.ObjectPath)11 List (java.util.List)10 CatalogTable (org.apache.flink.table.catalog.CatalogTable)10 Path (org.apache.flink.core.fs.Path)8 CatalogBaseTable (org.apache.flink.table.catalog.CatalogBaseTable)8 CatalogPartition (org.apache.flink.table.catalog.CatalogPartition)7 Test (org.junit.Test)7 HashSet (java.util.HashSet)6 SqlCreateHiveTable (org.apache.flink.sql.parser.hive.ddl.SqlCreateHiveTable)6 CatalogPartitionImpl (org.apache.flink.table.catalog.CatalogPartitionImpl)6 ObjectIdentifier (org.apache.flink.table.catalog.ObjectIdentifier)6 ValidationException (org.apache.flink.table.api.ValidationException)5 RowData (org.apache.flink.table.data.RowData)5 Partition (org.apache.hadoop.hive.metastore.api.Partition)5 Set (java.util.Set)4