Skip to content

Commit a1a4003

Browse files
committed
Add changes to populate the datasource metadata details
1 parent b566980 commit a1a4003

File tree

11 files changed

+206
-36
lines changed

11 files changed

+206
-36
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package com.facebook.presto.plugin.jdbc;
16+
17+
import com.fasterxml.jackson.annotation.JsonProperty;
18+
19+
import static java.util.Objects.requireNonNull;
20+
21+
public class JdbcInputInfo
22+
{
23+
private final String tableLocation;
24+
private final String tableName;
25+
26+
public JdbcInputInfo(
27+
@JsonProperty("tableLocation") String tableLocation,
28+
@JsonProperty("tableName") String tableName)
29+
30+
{
31+
this.tableLocation = requireNonNull(tableLocation, "tableLocation is null");
32+
this.tableName = requireNonNull(tableName, "tableName is null");
33+
}
34+
35+
@JsonProperty
36+
public String getTableLocation()
37+
{
38+
return tableLocation;
39+
}
40+
}

presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/JdbcMetadata.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,16 @@ public class JdbcMetadata
5555
private final JdbcMetadataCache jdbcMetadataCache;
5656
private final JdbcClient jdbcClient;
5757
private final boolean allowDropTable;
58+
private final BaseJdbcConfig baseJdbcConfig;
5859

5960
private final AtomicReference<Runnable> rollbackAction = new AtomicReference<>();
6061

61-
public JdbcMetadata(JdbcMetadataCache jdbcMetadataCache, JdbcClient jdbcClient, boolean allowDropTable)
62+
public JdbcMetadata(JdbcMetadataCache jdbcMetadataCache, JdbcClient jdbcClient, boolean allowDropTable, BaseJdbcConfig baseJdbcConfig)
6263
{
6364
this.jdbcMetadataCache = requireNonNull(jdbcMetadataCache, "jdbcMetadataCache is null");
6465
this.jdbcClient = requireNonNull(jdbcClient, "client is null");
6566
this.allowDropTable = allowDropTable;
67+
this.baseJdbcConfig = requireNonNull(baseJdbcConfig, "baseJdbcConfig is null");
6668
}
6769

6870
@Override
@@ -188,8 +190,9 @@ public Optional<ConnectorOutputMetadata> finishCreateTable(ConnectorSession sess
188190
{
189191
JdbcOutputTableHandle handle = (JdbcOutputTableHandle) tableHandle;
190192
jdbcClient.commitCreateTable(session, JdbcIdentity.from(session), handle);
193+
String url = baseJdbcConfig.getConnectionUrl();
191194
clearRollback();
192-
return Optional.empty();
195+
return Optional.of(new JdbcOutputMetadata(url));
193196
}
194197

195198
private void setRollback(Runnable action)
@@ -267,4 +270,12 @@ public TableStatistics getTableStatistics(ConnectorSession session, ConnectorTab
267270
List<JdbcColumnHandle> columns = columnHandles.stream().map(JdbcColumnHandle.class::cast).collect(Collectors.toList());
268271
return jdbcClient.getTableStatistics(session, handle, columns, constraint.getSummary());
269272
}
273+
274+
@Override
275+
public Optional<Object> getInfo(ConnectorTableLayoutHandle tableHandle)
276+
{
277+
JdbcTableLayoutHandle jdbcTableLayoutHandle = (JdbcTableLayoutHandle) tableHandle;
278+
String tableLocation = baseJdbcConfig.getConnectionUrl();
279+
return Optional.of(new JdbcInputInfo(tableLocation, jdbcTableLayoutHandle.getTable().getTableName()));
280+
}
270281
}

presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/JdbcMetadataFactory.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,20 @@ public class JdbcMetadataFactory
2222
private final JdbcMetadataCache jdbcMetadataCache;
2323
private final JdbcClient jdbcClient;
2424
private final boolean allowDropTable;
25+
private final BaseJdbcConfig baseJdbcConfig;
2526

2627
@Inject
27-
public JdbcMetadataFactory(JdbcMetadataCache jdbcMetadataCache, JdbcClient jdbcClient, JdbcMetadataConfig config)
28+
public JdbcMetadataFactory(JdbcMetadataCache jdbcMetadataCache, JdbcClient jdbcClient, JdbcMetadataConfig config, BaseJdbcConfig baseJdbcConfig)
2829
{
2930
this.jdbcMetadataCache = requireNonNull(jdbcMetadataCache, "jdbcMetadataCache is null");
3031
this.jdbcClient = requireNonNull(jdbcClient, "jdbcClient is null");
3132
requireNonNull(config, "config is null");
3233
this.allowDropTable = config.isAllowDropTable();
34+
this.baseJdbcConfig = requireNonNull(baseJdbcConfig, "baseJdbcConfig is null");
3335
}
3436

3537
public JdbcMetadata create()
3638
{
37-
return new JdbcMetadata(jdbcMetadataCache, jdbcClient, allowDropTable);
39+
return new JdbcMetadata(jdbcMetadataCache, jdbcClient, allowDropTable, baseJdbcConfig);
3840
}
3941
}

presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergWrittenPartitions.java renamed to presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/JdbcOutputMetadata.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,30 @@
1111
* See the License for the specific language governing permissions and
1212
* limitations under the License.
1313
*/
14-
package com.facebook.presto.iceberg;
14+
15+
package com.facebook.presto.plugin.jdbc;
1516

1617
import com.facebook.presto.spi.connector.ConnectorOutputMetadata;
1718
import com.fasterxml.jackson.annotation.JsonCreator;
1819
import com.fasterxml.jackson.annotation.JsonProperty;
19-
import com.google.common.collect.ImmutableList;
20-
21-
import java.util.List;
2220

2321
import static java.util.Objects.requireNonNull;
2422

25-
public class IcebergWrittenPartitions
23+
public class JdbcOutputMetadata
2624
implements ConnectorOutputMetadata
2725
{
28-
private final List<String> partitionNames;
26+
private final String tableLocation;
2927

3028
@JsonCreator
31-
public IcebergWrittenPartitions(@JsonProperty("partitionNames") List<String> partitionNames)
29+
public JdbcOutputMetadata(@JsonProperty("tableLocation") String tableLocation)
3230
{
33-
this.partitionNames = ImmutableList.copyOf(requireNonNull(partitionNames, "partitionNames is null"));
31+
this.tableLocation = requireNonNull(tableLocation, "tableLocation is null");
3432
}
3533

3634
@JsonProperty
37-
public List<String> getInfo()
35+
@Override
36+
public String getInfo()
3837
{
39-
return partitionNames;
38+
return tableLocation;
4039
}
4140
}

presto-base-jdbc/src/test/java/com/facebook/presto/plugin/jdbc/TestJdbcMetadata.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void setUp()
6666
database = new TestingDatabase();
6767
ListeningExecutorService executor = listeningDecorator(newCachedThreadPool(daemonThreadsNamed("test-%s")));
6868
jdbcMetadataCache = new JdbcMetadataCache(executor, database.getJdbcClient(), new JdbcMetadataCacheStats(), OptionalLong.of(0), OptionalLong.of(0), 100);
69-
metadata = new JdbcMetadata(jdbcMetadataCache, database.getJdbcClient(), false);
69+
metadata = new JdbcMetadata(jdbcMetadataCache, database.getJdbcClient(), false, new BaseJdbcConfig());
7070
tableHandle = metadata.getTableHandle(SESSION, new SchemaTableName("example", "numbers"));
7171
}
7272

@@ -261,7 +261,7 @@ public void testDropTableTable()
261261
assertEquals(e.getErrorCode(), PERMISSION_DENIED.toErrorCode());
262262
}
263263

264-
metadata = new JdbcMetadata(jdbcMetadataCache, database.getJdbcClient(), true);
264+
metadata = new JdbcMetadata(jdbcMetadataCache, database.getJdbcClient(), true, new BaseJdbcConfig());
265265
metadata.dropTable(SESSION, tableHandle);
266266

267267
try {
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package com.facebook.presto.hive;
16+
17+
import com.fasterxml.jackson.annotation.JsonCreator;
18+
import com.fasterxml.jackson.annotation.JsonProperty;
19+
import com.google.common.collect.ImmutableList;
20+
21+
import java.util.List;
22+
import java.util.Objects;
23+
24+
import static java.util.Objects.requireNonNull;
25+
26+
public class HiveOutputInfo
27+
{
28+
private final List<String> partitionNames;
29+
private final String tableLocation;
30+
31+
@JsonCreator
32+
public HiveOutputInfo(
33+
@JsonProperty("partitionNames") List<String> partitionNames,
34+
@JsonProperty("tableLocation") String tableLocation)
35+
{
36+
this.partitionNames = ImmutableList.copyOf(requireNonNull(partitionNames, "partitionNames is null"));
37+
this.tableLocation = requireNonNull(tableLocation, "tableLocation is null");
38+
}
39+
40+
@JsonProperty
41+
public List<String> getPartitionNames()
42+
{
43+
return partitionNames;
44+
}
45+
46+
@JsonProperty
47+
public String getTableLocation()
48+
{
49+
return tableLocation;
50+
}
51+
52+
@Override
53+
public boolean equals(Object o)
54+
{
55+
if (o == null || getClass() != o.getClass()) {
56+
return false;
57+
}
58+
HiveOutputInfo that = (HiveOutputInfo) o;
59+
return Objects.equals(partitionNames, that.partitionNames) && Objects.equals(tableLocation, that.tableLocation);
60+
}
61+
62+
@Override
63+
public int hashCode()
64+
{
65+
return Objects.hash(partitionNames, tableLocation);
66+
}
67+
68+
@Override
69+
public String toString()
70+
{
71+
return "HiveOutputInfo{" +
72+
"partitionNames=" + partitionNames +
73+
", tableLocation='" + tableLocation + '\'' +
74+
'}';
75+
}
76+
}

presto-hive/src/main/java/com/facebook/presto/hive/HiveWrittenPartitions.java renamed to presto-hive-common/src/main/java/com/facebook/presto/hive/HiveWrittenPartitions.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,24 @@
1616
import com.facebook.presto.spi.connector.ConnectorOutputMetadata;
1717
import com.fasterxml.jackson.annotation.JsonCreator;
1818
import com.fasterxml.jackson.annotation.JsonProperty;
19-
import com.google.common.collect.ImmutableList;
20-
21-
import java.util.List;
2219

2320
import static java.util.Objects.requireNonNull;
2421

2522
public class HiveWrittenPartitions
2623
implements ConnectorOutputMetadata
2724
{
28-
private final List<String> partitionNames;
25+
private final HiveOutputInfo hiveOutputInfo;
2926

3027
@JsonCreator
31-
public HiveWrittenPartitions(@JsonProperty("partitionNames") List<String> partitionNames)
28+
public HiveWrittenPartitions(@JsonProperty("hiveOutputInfo") HiveOutputInfo hiveOutputInfo)
3229
{
33-
this.partitionNames = ImmutableList.copyOf(requireNonNull(partitionNames, "partitionNames is null"));
30+
this.hiveOutputInfo = requireNonNull(hiveOutputInfo, "hiveOutputInfo is null");
3431
}
3532

3633
@JsonProperty
37-
public List<String> getInfo()
34+
@Override
35+
public HiveOutputInfo getInfo()
3836
{
39-
return partitionNames;
37+
return hiveOutputInfo;
4038
}
4139
}

presto-hive/src/main/java/com/facebook/presto/hive/HiveInputInfo.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@ public class HiveInputInfo
2424
// Code that serialize HiveInputInfo into log would often need the ability to limit the length of log entries.
2525
// This boolean field allows such code to mark the log entry as length limited.
2626
private final boolean truncated;
27+
private final String tableLocation;
2728

2829
@JsonCreator
2930
public HiveInputInfo(
3031
@JsonProperty("partitionIds") List<String> partitionIds,
31-
@JsonProperty("truncated") boolean truncated)
32+
@JsonProperty("truncated") boolean truncated,
33+
@JsonProperty("tableLocation") String tableLocation)
3234
{
3335
this.partitionIds = partitionIds;
3436
this.truncated = truncated;
37+
this.tableLocation = tableLocation;
3538
}
3639

3740
@JsonProperty
@@ -45,4 +48,10 @@ public boolean isTruncated()
4548
{
4649
return truncated;
4750
}
51+
52+
@JsonProperty
53+
public String getTableLocation()
54+
{
55+
return tableLocation;
56+
}
4857
}

presto-hive/src/main/java/com/facebook/presto/hive/HiveMetadata.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ public Optional<Object> getInfo(ConnectorTableLayoutHandle layoutHandle)
808808
tableLayoutHandle.getPartitions().get().stream()
809809
.map(hivePartition -> hivePartition.getPartitionId().getPartitionName())
810810
.collect(toList()),
811-
false));
811+
false, tableLayoutHandle.getTablePath()));
812812
}
813813

814814
return Optional.empty();
@@ -1756,7 +1756,7 @@ public Optional<ConnectorOutputMetadata> finishCreateTable(ConnectorSession sess
17561756
metastore.createTable(session, table, principalPrivileges, Optional.of(writeInfo.getWritePath()), false, tableStatistics, emptyList());
17571757

17581758
if (handle.getPartitionedBy().isEmpty()) {
1759-
return Optional.of(new HiveWrittenPartitions(ImmutableList.of(UNPARTITIONED_ID.getPartitionName())));
1759+
return Optional.of(new HiveWrittenPartitions(new HiveOutputInfo(ImmutableList.of(UNPARTITIONED_ID.getPartitionName()), writeInfo.getTargetPath().toString())));
17601760
}
17611761

17621762
if (isRespectTableFormat(session)) {
@@ -1785,10 +1785,10 @@ public Optional<ConnectorOutputMetadata> finishCreateTable(ConnectorSession sess
17851785
partitionStatistics);
17861786
}
17871787

1788-
return Optional.of(new HiveWrittenPartitions(
1788+
return Optional.of(new HiveWrittenPartitions(new HiveOutputInfo(
17891789
partitionUpdates.stream()
17901790
.map(PartitionUpdate::getName)
1791-
.collect(toList())));
1791+
.collect(toList()), writeInfo.getTargetPath().toString())));
17921792
}
17931793

17941794
public static boolean shouldCreateFilesForMissingBuckets(Table table, ConnectorSession session)
@@ -2196,11 +2196,11 @@ else if (partitionUpdate.getUpdateMode() == NEW || partitionUpdate.getUpdateMode
21962196
}
21972197
}
21982198

2199-
return Optional.of(new HiveWrittenPartitions(
2199+
return Optional.of(new HiveWrittenPartitions(new HiveOutputInfo(
22002200
partitionUpdates.stream()
22012201
.map(PartitionUpdate::getName)
22022202
.map(name -> name.isEmpty() ? UNPARTITIONED_ID.getPartitionName() : name)
2203-
.collect(toList())));
2203+
.collect(toList()), table.getStorage().getLocation())));
22042204
}
22052205

22062206
/**

0 commit comments

Comments
 (0)