Skip to content

Commit d8df515

Browse files
committed
v1
1 parent 974b725 commit d8df515

File tree

27 files changed

+154
-59
lines changed

27 files changed

+154
-59
lines changed

paimon-common/src/main/java/org/apache/paimon/catalog/CatalogContext.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,21 @@ public class CatalogContext implements Serializable {
4848
private final SerializableConfiguration hadoopConf;
4949
@Nullable private final FileIOLoader preferIOLoader;
5050
@Nullable private final FileIOLoader fallbackIOLoader;
51+
@Nullable private final String catalogName;
5152

5253
private CatalogContext(
5354
Options options,
5455
@Nullable Configuration hadoopConf,
5556
@Nullable FileIOLoader preferIOLoader,
56-
@Nullable FileIOLoader fallbackIOLoader) {
57+
@Nullable FileIOLoader fallbackIOLoader,
58+
@Nullable String catalogName) {
5759
this.options = checkNotNull(options);
5860
this.hadoopConf =
5961
new SerializableConfiguration(
6062
hadoopConf == null ? getHadoopConfiguration(options) : hadoopConf);
6163
this.preferIOLoader = preferIOLoader;
6264
this.fallbackIOLoader = fallbackIOLoader;
65+
this.catalogName = catalogName;
6366
}
6467

6568
public static CatalogContext create(Path warehouse) {
@@ -69,28 +72,43 @@ public static CatalogContext create(Path warehouse) {
6972
}
7073

7174
public static CatalogContext create(Options options) {
72-
return new CatalogContext(options, null, null, null);
75+
return new CatalogContext(options, null, null, null, null);
7376
}
7477

7578
public static CatalogContext create(Options options, Configuration hadoopConf) {
76-
return new CatalogContext(options, hadoopConf, null, null);
79+
return new CatalogContext(options, hadoopConf, null, null, null);
80+
}
81+
82+
public static CatalogContext create(
83+
Options options, Configuration hadoopConf, @Nullable String catalogName) {
84+
return new CatalogContext(options, hadoopConf, null, null, catalogName);
7785
}
7886

7987
public static CatalogContext create(Options options, FileIOLoader fallbackIOLoader) {
80-
return new CatalogContext(options, null, null, fallbackIOLoader);
88+
return new CatalogContext(options, null, null, fallbackIOLoader, null);
8189
}
8290

8391
public static CatalogContext create(
8492
Options options, FileIOLoader preferIOLoader, FileIOLoader fallbackIOLoader) {
85-
return new CatalogContext(options, null, preferIOLoader, fallbackIOLoader);
93+
return new CatalogContext(options, null, preferIOLoader, fallbackIOLoader, null);
94+
}
95+
96+
public static CatalogContext create(
97+
Options options,
98+
FileIOLoader preferIOLoader,
99+
FileIOLoader fallbackIOLoader,
100+
@Nullable String catalogName) {
101+
return new CatalogContext(options, null, preferIOLoader, fallbackIOLoader, catalogName);
86102
}
87103

88104
public static CatalogContext create(
89105
Options options,
90106
Configuration hadoopConf,
91107
FileIOLoader preferIOLoader,
92-
FileIOLoader fallbackIOLoader) {
93-
return new CatalogContext(options, hadoopConf, preferIOLoader, fallbackIOLoader);
108+
FileIOLoader fallbackIOLoader,
109+
@Nullable String catalogName) {
110+
return new CatalogContext(
111+
options, hadoopConf, preferIOLoader, fallbackIOLoader, catalogName);
94112
}
95113

96114
public Options options() {
@@ -111,4 +129,9 @@ public FileIOLoader preferIO() {
111129
public FileIOLoader fallbackIO() {
112130
return fallbackIOLoader;
113131
}
132+
133+
@Nullable
134+
public String catalogName() {
135+
return catalogName;
136+
}
114137
}

paimon-common/src/main/java/org/apache/paimon/fs/ResolvingFileIO.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ public void configure(CatalogContext context) {
6464
options.set(RESOLVING_FILE_IO_ENABLED, false);
6565
this.context =
6666
CatalogContext.create(
67-
options, context.hadoopConf(), context.preferIO(), context.fallbackIO());
67+
options,
68+
context.hadoopConf(),
69+
context.preferIO(),
70+
context.fallbackIO(),
71+
context.catalogName());
6872
}
6973

7074
@Override

paimon-common/src/main/java/org/apache/paimon/rest/RESTTokenFileIO.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ public FileIO fileIO() throws IOException {
181181
options,
182182
catalogContext.hadoopConf(),
183183
catalogContext.preferIO(),
184-
catalogContext.fallbackIO());
184+
catalogContext.fallbackIO(),
185+
catalogContext.catalogName());
185186
try {
186187
fileIO = FileIO.get(path, context);
187188
} catch (IOException e) {

paimon-core/src/main/java/org/apache/paimon/catalog/AbstractCatalog.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ protected AbstractCatalog(FileIO fileIO, CatalogContext context) {
9595
this.context = context;
9696
}
9797

98+
@Nullable
99+
@Override
100+
public String name() {
101+
return context.catalogName();
102+
}
103+
98104
@Override
99105
public Map<String, String> options() {
100106
return context.options().toMap();

paimon-core/src/main/java/org/apache/paimon/catalog/Catalog.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,10 @@ TableQueryAuthResult authTableQuery(Identifier identifier, @Nullable List<String
11661166

11671167
// ==================== Catalog Information ==========================
11681168

1169+
/** The name of this catalog. */
1170+
@Nullable
1171+
String name();
1172+
11691173
/** Catalog options for re-creating this catalog. */
11701174
Map<String, String> options();
11711175

paimon-core/src/main/java/org/apache/paimon/catalog/CatalogUtils.java

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import org.apache.paimon.table.system.SystemTableLoader;
4848
import org.apache.paimon.types.DataField;
4949
import org.apache.paimon.utils.InternalRowPartitionComputer;
50-
import org.apache.paimon.utils.Pair;
5150
import org.apache.paimon.utils.Preconditions;
5251

5352
import javax.annotation.Nullable;
@@ -292,6 +291,7 @@ public static Table loadTable(
292291

293292
CatalogEnvironment catalogEnv =
294293
new CatalogEnvironment(
294+
catalog.name(),
295295
tableIdentifier,
296296
metadata.uuid(),
297297
isRestCatalog && metadata.isExternal() ? null : catalog.catalogLoader(),
@@ -315,15 +315,17 @@ private static Table createGlobalSystemTable(String tableName, Catalog catalog)
315315
throws Catalog.TableNotExistException {
316316
switch (tableName.toLowerCase()) {
317317
case ALL_TABLE_OPTIONS:
318-
List<Table> tables = listAllTables(catalog);
318+
Map<Identifier, Table> tables = listAllTables(catalog);
319319
Map<Identifier, Map<String, String>> allOptions = new HashMap<>();
320-
for (Table table : tables) {
321-
allOptions.put(Identifier.fromString(table.fullName()), table.options());
320+
for (Map.Entry<Identifier, Table> entry : tables.entrySet()) {
321+
allOptions.put(entry.getKey(), entry.getValue().options());
322322
}
323323
return new AllTableOptionsTable(allOptions);
324324
case ALL_TABLES:
325-
return AllTablesTable.fromTables(
326-
toTableAndSnapshots(catalog, listAllTables(catalog)));
325+
Map<Identifier, Table> allTablesForDisplay = listAllTables(catalog);
326+
Map<Identifier, TableSnapshot> snapshots =
327+
toTableSnapshots(catalog, allTablesForDisplay);
328+
return AllTablesTable.fromTables(allTablesForDisplay, snapshots);
327329
case ALL_PARTITIONS:
328330
return AllPartitionsTable.fromPartitions(
329331
toAllPartitions(catalog, listAllTables(catalog)));
@@ -335,50 +337,49 @@ private static Table createGlobalSystemTable(String tableName, Catalog catalog)
335337
}
336338
}
337339

338-
private static List<Table> listAllTables(Catalog catalog) {
339-
List<Table> tables = new ArrayList<>();
340+
private static Map<Identifier, Table> listAllTables(Catalog catalog) {
341+
Map<Identifier, Table> tables = new HashMap<>();
340342
for (String database : catalog.listDatabases()) {
341343
try {
342344
for (String name : catalog.listTables(database)) {
343-
tables.add(catalog.getTable(Identifier.create(database, name)));
345+
Identifier identifier = Identifier.create(database, name);
346+
tables.put(identifier, catalog.getTable(identifier));
344347
}
345348
} catch (Catalog.DatabaseNotExistException | Catalog.TableNotExistException ignored) {
346349
}
347350
}
348351
return tables;
349352
}
350353

351-
private static List<Pair<Table, TableSnapshot>> toTableAndSnapshots(
352-
Catalog catalog, List<Table> tables) {
353-
List<Pair<Table, TableSnapshot>> tableAndSnapshots = new ArrayList<>();
354-
for (Table table : tables) {
355-
TableSnapshot snapshot = null;
354+
private static Map<Identifier, TableSnapshot> toTableSnapshots(
355+
Catalog catalog, Map<Identifier, Table> tables) {
356+
Map<Identifier, TableSnapshot> snapshots = new HashMap<>();
357+
for (Identifier identifier : tables.keySet()) {
356358
if (catalog.supportsVersionManagement()) {
357359
try {
358-
Optional<TableSnapshot> optional =
359-
catalog.loadSnapshot(Identifier.fromString(table.fullName()));
360+
Optional<TableSnapshot> optional = catalog.loadSnapshot(identifier);
360361
if (optional.isPresent()) {
361-
snapshot = optional.get();
362+
snapshots.put(identifier, optional.get());
362363
}
363364
} catch (Catalog.TableNotExistException ignored) {
364365
} catch (NotImplementedException ignored) {
365366
// does not support supportsVersionManagement for external paimon table
366367
}
367368
}
368-
tableAndSnapshots.add(Pair.of(table, snapshot));
369369
}
370-
return tableAndSnapshots;
370+
return snapshots;
371371
}
372372

373373
private static Map<Identifier, List<Partition>> toAllPartitions(
374-
Catalog catalog, List<Table> tables) {
374+
Catalog catalog, Map<Identifier, Table> tables) {
375375
Map<Identifier, List<Partition>> allPartitions = new HashMap<>();
376-
for (Table table : tables) {
376+
for (Map.Entry<Identifier, Table> entry : tables.entrySet()) {
377+
Table table = entry.getValue();
377378
if (table.partitionKeys().isEmpty()) {
378379
continue;
379380
}
380381

381-
Identifier identifier = Identifier.fromString(table.fullName());
382+
Identifier identifier = entry.getKey();
382383
try {
383384
List<Partition> partitions = catalog.listPartitions(identifier);
384385
allPartitions.put(identifier, partitions);

paimon-core/src/main/java/org/apache/paimon/catalog/DelegateCatalog.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ public Catalog wrapped() {
5353
return wrapped;
5454
}
5555

56+
@Nullable
57+
@Override
58+
public String name() {
59+
return wrapped.name();
60+
}
61+
5662
@Override
5763
public boolean caseSensitive() {
5864
return wrapped.caseSensitive();

paimon-core/src/main/java/org/apache/paimon/partition/actions/HttpReportMarkDoneAction.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ public void open(FileStoreTable fileStoreTable, CoreOptions options) {
6565

6666
this.params = options.httpReportMarkDoneActionParams();
6767
this.url = options.httpReportMarkDoneActionUrl();
68-
this.tableName = fileStoreTable.fullName();
68+
// just for compatibility with the old behavior
69+
String fullName = fileStoreTable.fullName();
70+
String[] parts = fullName.split("\\.");
71+
this.tableName = parts.length == 3 ? parts[1] + "." + parts[2] : fullName;
6972
this.location = fileStoreTable.location().toString();
7073

7174
this.mapper = new ObjectMapper();

paimon-core/src/main/java/org/apache/paimon/rest/RESTCatalog.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,17 @@ public RESTCatalog(CatalogContext context, boolean configRequired) {
113113
api.options(),
114114
context.hadoopConf(),
115115
context.preferIO(),
116-
context.fallbackIO());
116+
context.fallbackIO(),
117+
context.catalogName());
117118
this.dataTokenEnabled = api.options().get(RESTTokenFileIO.DATA_TOKEN_ENABLED);
118119
this.tableDefaultOptions = CatalogUtils.tableDefaultOptions(this.context.options().toMap());
119120
}
120121

122+
@Override
123+
public String name() {
124+
return context.catalogName();
125+
}
126+
121127
@Override
122128
public Map<String, String> options() {
123129
return context.options().toMap();

paimon-core/src/main/java/org/apache/paimon/table/AbstractFileStoreTable.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,12 @@ public String name() {
180180

181181
@Override
182182
public String fullName() {
183-
return identifier().getFullName();
183+
String catalogName = catalogEnvironment.catalogName();
184+
String identifierFullName = identifier().getFullName();
185+
if (catalogName != null) {
186+
return catalogName + "." + identifierFullName;
187+
}
188+
return identifierFullName;
184189
}
185190

186191
public Identifier identifier() {

0 commit comments

Comments
 (0)