16
16
import com .facebook .presto .Session ;
17
17
import com .facebook .presto .Session .SessionBuilder ;
18
18
import com .facebook .presto .common .type .TimeZoneKey ;
19
+ import com .facebook .presto .hive .HdfsEnvironment ;
20
+ import com .facebook .presto .hive .HiveClientConfig ;
21
+ import com .facebook .presto .hive .MetastoreClientConfig ;
22
+ import com .facebook .presto .hive .s3 .HiveS3Config ;
19
23
import com .facebook .presto .metadata .CatalogManager ;
20
24
import com .facebook .presto .spi .ConnectorId ;
21
25
import com .facebook .presto .spi .ConnectorSession ;
26
+ import com .facebook .presto .spi .SchemaTableName ;
22
27
import com .facebook .presto .testing .MaterializedResult ;
23
28
import com .facebook .presto .testing .QueryRunner ;
24
29
import com .facebook .presto .testing .assertions .Assert ;
25
30
import com .facebook .presto .tests .AbstractTestIntegrationSmokeTest ;
31
+ import org .apache .hadoop .fs .FileSystem ;
26
32
import org .apache .hadoop .fs .Path ;
27
33
import org .apache .iceberg .Table ;
28
34
import org .apache .iceberg .UpdateProperties ;
43
49
import static com .facebook .presto .iceberg .IcebergQueryRunner .getIcebergDataDirectoryPath ;
44
50
import static com .facebook .presto .iceberg .IcebergUtil .MIN_FORMAT_VERSION_FOR_DELETE ;
45
51
import static com .facebook .presto .iceberg .procedure .RegisterTableProcedure .METADATA_FOLDER_NAME ;
46
- import static com .facebook .presto .iceberg .procedure .TestIcebergRegisterAndUnregisterProcedure .getMetadataFileLocation ;
52
+ import static com .facebook .presto .iceberg .procedure .RegisterTableProcedure .getFileSystem ;
53
+ import static com .facebook .presto .iceberg .procedure .RegisterTableProcedure .resolveLatestMetadataLocation ;
47
54
import static com .facebook .presto .testing .MaterializedResult .resultBuilder ;
48
55
import static com .google .common .base .Preconditions .checkArgument ;
49
56
import static com .google .common .collect .Iterables .getOnlyElement ;
53
60
import static java .util .Objects .requireNonNull ;
54
61
import static java .util .stream .Collectors .joining ;
55
62
import static java .util .stream .IntStream .range ;
63
+ import static org .apache .iceberg .util .LocationUtil .stripTrailingSlash ;
56
64
import static org .assertj .core .api .Assertions .assertThat ;
57
65
import static org .assertj .core .api .Assertions .assertThatThrownBy ;
58
66
import static org .testng .Assert .assertEquals ;
@@ -1606,7 +1614,7 @@ public void testRegisterTableWithFileName()
1606
1614
assertUpdate ("INSERT INTO " + tableName + " VALUES(1, 1)" , 1 );
1607
1615
1608
1616
String metadataLocation = getLocation (schemaName , tableName );
1609
- String metadataFileName = getMetadataFileLocation (getSession ().toConnectorSession (), schemaName , tableName , metadataLocation );
1617
+ String metadataFileName = getMetadataFileLocation (getSession ().toConnectorSession (), getHdfsEnvironment (), schemaName , tableName , metadataLocation );
1610
1618
1611
1619
// Register new table with procedure
1612
1620
String newTableName = tableName + "_new" ;
@@ -1625,7 +1633,7 @@ public void testRegisterTableWithInvalidLocation()
1625
1633
assertUpdate ("CREATE TABLE " + tableName + " (id integer, value integer)" );
1626
1634
assertUpdate ("INSERT INTO " + tableName + " VALUES(1, 1)" , 1 );
1627
1635
1628
- String metadataLocation = getLocation (schemaName , tableName ). replace ( "//" , "" ) + "_invalid" ;
1636
+ String metadataLocation = getLocation (schemaName , tableName ) + "_invalid" ;
1629
1637
1630
1638
@ Language ("RegExp" ) String errorMessage = format ("Unable to find metadata at location %s/%s" , metadataLocation , METADATA_FOLDER_NAME );
1631
1639
assertQueryFails ("CALL system.register_table ('" + schemaName + "', '" + tableName + "', '" + metadataLocation + "')" , errorMessage );
@@ -2020,4 +2028,23 @@ public void testUpdateNonExistentTable()
2020
2028
assertQueryFails ("ALTER TABLE non_existent_test_table2 SET PROPERTIES (commit_retries = 6)" ,
2021
2029
format ("Table does not exist: iceberg.%s.non_existent_test_table2" , getSession ().getSchema ().get ()));
2022
2030
}
2031
+
2032
+ protected HdfsEnvironment getHdfsEnvironment ()
2033
+ {
2034
+ HiveClientConfig hiveClientConfig = new HiveClientConfig ();
2035
+ MetastoreClientConfig metastoreClientConfig = new MetastoreClientConfig ();
2036
+ HiveS3Config hiveS3Config = new HiveS3Config ();
2037
+ return IcebergDistributedTestBase .getHdfsEnvironment (hiveClientConfig , metastoreClientConfig , hiveS3Config );
2038
+ }
2039
+
2040
+ private static String getMetadataFileLocation (ConnectorSession session , HdfsEnvironment hdfsEnvironment , String schema , String table , String metadataLocation )
2041
+ {
2042
+ metadataLocation = stripTrailingSlash (metadataLocation );
2043
+ org .apache .hadoop .fs .Path metadataDir = new org .apache .hadoop .fs .Path (metadataLocation , METADATA_FOLDER_NAME );
2044
+ FileSystem fileSystem = getFileSystem (session , hdfsEnvironment , new SchemaTableName (schema , table ), metadataDir );
2045
+ return resolveLatestMetadataLocation (
2046
+ session ,
2047
+ fileSystem ,
2048
+ metadataDir ).getName ();
2049
+ }
2023
2050
}
0 commit comments