Skip to content

Commit

Permalink
list partitions check options use table options
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry-024 committed Dec 30, 2024
1 parent 9c7139b commit ccd53b2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,11 @@ public void dropPartition(Identifier identifier, Map<String, String> partitions)
@Override
public List<PartitionEntry> listPartitions(Identifier identifier)
throws TableNotExistException {
FileStoreTable table = (FileStoreTable) getTable(identifier);
boolean whetherSupportListPartitions =
context.options().get(CoreOptions.METASTORE_PARTITIONED_TABLE);
Boolean.parseBoolean(
table.options().get(CoreOptions.METASTORE_PARTITIONED_TABLE.key()));
if (whetherSupportListPartitions) {
FileStoreTable table = (FileStoreTable) getTable(identifier);
RowType rowType = table.schema().logicalPartitionType();
return listPartitionsFromServer(identifier, rowType);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.apache.paimon.rest;

import org.apache.paimon.CoreOptions;
import org.apache.paimon.catalog.Identifier;
import org.apache.paimon.rest.requests.AlterDatabaseRequest;
import org.apache.paimon.rest.requests.AlterTableRequest;
Expand Down Expand Up @@ -227,20 +228,27 @@ public static List<SchemaChange> getChanges() {
return schemaChanges;
}

public static GetTableResponse getTableResponseEnablePartition() {
Map<String, String> options = new HashMap<>();
options.put("option-1", "value-1");
options.put(CoreOptions.METASTORE_PARTITIONED_TABLE.key(), "true");
return new GetTableResponse("/tmp/2", 1, schema(options));
}

public static GetTableResponse getTableResponse() {
return new GetTableResponse("/tmp/1", 1, schema());
Map<String, String> options = new HashMap<>();
options.put("option-1", "value-1");
options.put("option-2", "value-2");
return new GetTableResponse("/tmp/1", 1, schema(options));
}

private static Schema schema() {
private static Schema schema(Map<String, String> options) {
List<DataField> fields =
Arrays.asList(
new DataField(0, "f0", new IntType()),
new DataField(1, "f1", new IntType()));
List<String> partitionKeys = Collections.singletonList("f0");
List<String> primaryKeys = Arrays.asList("f0", "f1");
Map<String, String> options = new HashMap<>();
options.put("option-1", "value-1");
options.put("option-2", "value-2");
return new Schema(fields, partitionKeys, primaryKeys, options, "comment");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package org.apache.paimon.rest;

import org.apache.paimon.CoreOptions;
import org.apache.paimon.catalog.Catalog;
import org.apache.paimon.catalog.CatalogContext;
import org.apache.paimon.catalog.Database;
Expand Down Expand Up @@ -473,13 +472,8 @@ public void testDropPartitionWhenTableNoExist() throws Exception {

@Test
public void testListPartitionsWhenMetastorePartitionedIsTrue() throws Exception {
Options options = mockInitOptions();
options = options.set(CoreOptions.METASTORE_PARTITIONED_TABLE, true);
mockConfig(warehouseStr);
RESTCatalog restCatalog = new RESTCatalog(CatalogContext.create(options));
RESTCatalog mockRestCatalog = spy(restCatalog);
String databaseName = MockRESTMessage.databaseName();
GetTableResponse getTableResponse = MockRESTMessage.getTableResponse();
GetTableResponse getTableResponse = MockRESTMessage.getTableResponseEnablePartition();
mockResponse(mapper.writeValueAsString(getTableResponse), 200);
ListPartitionsResponse response = MockRESTMessage.listPartitionsResponse();
mockResponse(mapper.writeValueAsString(response), 200);
Expand All @@ -494,8 +488,9 @@ public void testListPartitionsFromFile() throws Exception {
String databaseName = MockRESTMessage.databaseName();
GetTableResponse response = MockRESTMessage.getTableResponse();
mockResponse(mapper.writeValueAsString(response), 200);
mockResponse(mapper.writeValueAsString(response), 200);
mockRestCatalog.listPartitions(Identifier.create(databaseName, "table"));
verify(mockRestCatalog, times(1)).getTable(any());
verify(mockRestCatalog, times(2)).getTable(any());
verify(mockRestCatalog, times(0)).listPartitionsFromServer(any(), any());
}

Expand Down

0 comments on commit ccd53b2

Please sign in to comment.