|
18 | 18 | import com.facebook.presto.hive.filesystem.ExtendedFileSystem;
|
19 | 19 | import com.facebook.presto.hive.metastore.Storage;
|
20 | 20 | import com.facebook.presto.hive.metastore.Table;
|
| 21 | +import com.facebook.presto.spi.ConnectorSession; |
21 | 22 | import com.facebook.presto.spi.security.ConnectorIdentity;
|
| 23 | +import com.facebook.presto.testing.TestingConnectorSession; |
22 | 24 | import com.google.common.collect.ImmutableList;
|
23 | 25 | import com.google.common.collect.ImmutableMap;
|
24 | 26 | import org.apache.hadoop.conf.Configuration;
|
|
33 | 35 | import java.io.IOException;
|
34 | 36 | import java.net.URI;
|
35 | 37 | import java.util.Iterator;
|
| 38 | +import java.util.List; |
36 | 39 | import java.util.Optional;
|
37 | 40 |
|
38 | 41 | import static com.facebook.presto.hive.BucketFunctionType.HIVE_COMPATIBLE;
|
39 | 42 | import static com.facebook.presto.hive.HiveStorageFormat.PARQUET;
|
40 | 43 | import static com.facebook.presto.hive.HiveTestUtils.SESSION;
|
| 44 | +import static com.facebook.presto.hive.HiveTestUtils.TEST_CLIENT_TAGS; |
| 45 | +import static com.facebook.presto.hive.HiveTestUtils.getAllSessionProperties; |
41 | 46 | import static com.facebook.presto.hive.NestedDirectoryPolicy.IGNORED;
|
42 | 47 | import static com.facebook.presto.hive.metastore.PrestoTableType.EXTERNAL_TABLE;
|
43 | 48 | import static com.facebook.presto.hive.metastore.StorageFormat.fromHiveStorageFormat;
|
44 | 49 | import static org.testng.Assert.assertEquals;
|
| 50 | +import static org.testng.Assert.assertFalse; |
45 | 51 | import static org.testng.Assert.assertThrows;
|
46 | 52 | import static org.testng.Assert.assertTrue;
|
47 | 53 |
|
@@ -107,6 +113,121 @@ private Table getMockTable()
|
107 | 113 | Optional.empty());
|
108 | 114 | }
|
109 | 115 |
|
| 116 | + private Table getMockMORTableWithPartition() |
| 117 | + { |
| 118 | + return new Table( |
| 119 | + "schema", |
| 120 | + "hudi_mor_part_update", |
| 121 | + "user", |
| 122 | + EXTERNAL_TABLE, |
| 123 | + new Storage(fromHiveStorageFormat(PARQUET), |
| 124 | + getTableBasePath("hudi_mor_part_update"), |
| 125 | + Optional.of(new HiveBucketProperty( |
| 126 | + ImmutableList.of(), |
| 127 | + 1, |
| 128 | + ImmutableList.of(), |
| 129 | + HIVE_COMPATIBLE, |
| 130 | + Optional.empty())), |
| 131 | + false, |
| 132 | + ImmutableMap.of(), |
| 133 | + ImmutableMap.of()), |
| 134 | + ImmutableList.of(), |
| 135 | + ImmutableList.of(), |
| 136 | + ImmutableMap.of(), |
| 137 | + Optional.empty(), |
| 138 | + Optional.empty()); |
| 139 | + } |
| 140 | + |
| 141 | + @Test |
| 142 | + public void testDirectoryListerForMORTableWithPartitionUpdates() |
| 143 | + throws IOException |
| 144 | + { |
| 145 | + Table mockTable = getMockMORTableWithPartition(); |
| 146 | + Configuration hadoopConf = getHadoopConfWithCopyOnFirstWriteDisabled(); |
| 147 | + try { |
| 148 | + ConnectorSession session = new TestingConnectorSession( |
| 149 | + getAllSessionProperties( |
| 150 | + new HiveClientConfig() |
| 151 | + .setHudiMetadataEnabled(true) |
| 152 | + .setHudiTablesUseMergedView(mockTable.getSchemaTableName().toString()), |
| 153 | + new HiveCommonClientConfig()), |
| 154 | + TEST_CLIENT_TAGS); |
| 155 | + HudiDirectoryLister directoryLister = new HudiDirectoryLister(hadoopConf, session, mockTable); |
| 156 | + HoodieTableMetaClient metaClient = directoryLister.getMetaClient(); |
| 157 | + assertEquals(metaClient.getBasePath(), mockTable.getStorage().getLocation()); |
| 158 | + Path path = new Path(mockTable.getStorage().getLocation()); |
| 159 | + ExtendedFileSystem fs = (ExtendedFileSystem) path.getFileSystem(hadoopConf); |
| 160 | + Iterator<HiveFileInfo> fileInfoIterator = directoryLister.list(fs, mockTable, path, Optional.empty(), new NamenodeStats(), new HiveDirectoryContext( |
| 161 | + IGNORED, |
| 162 | + false, |
| 163 | + false, |
| 164 | + new ConnectorIdentity("test", Optional.empty(), Optional.empty()), |
| 165 | + ImmutableMap.of(), |
| 166 | + new RuntimeStats())); |
| 167 | + while (fileInfoIterator.hasNext()) { |
| 168 | + HiveFileInfo fileInfo = fileInfoIterator.next(); |
| 169 | + String fileName = fileInfo.getFileName(); |
| 170 | + // expected to have the latest base file in p1 and p2 partitions |
| 171 | + assertTrue(fileName.startsWith("daf69bc6-01c8-4b86-b9ef-d9c036aa5cdc-0") || fileName.startsWith("bb70e1e1-8310-4ebe-8a9c-c955f8e72830-0")); |
| 172 | + // not expected to have the older version of the base file in p1 |
| 173 | + assertFalse(fileName.startsWith("c0bbff31-67b3-4660-99ba-d388b8bb8c3c-0_0-32-192")); |
| 174 | + } |
| 175 | + } |
| 176 | + finally { |
| 177 | + hadoopConf = null; |
| 178 | + } |
| 179 | + } |
| 180 | + |
| 181 | + @Test |
| 182 | + public void testDirectoryListerForMORTableWithoutTableNames() |
| 183 | + throws IOException |
| 184 | + { |
| 185 | + Table mockTable = getMockMORTableWithPartition(); |
| 186 | + Configuration hadoopConf = getHadoopConfWithCopyOnFirstWriteDisabled(); |
| 187 | + try { |
| 188 | + ConnectorSession session = new TestingConnectorSession( |
| 189 | + getAllSessionProperties( |
| 190 | + new HiveClientConfig() |
| 191 | + .setHudiMetadataEnabled(true), |
| 192 | + new HiveCommonClientConfig()), |
| 193 | + TEST_CLIENT_TAGS); |
| 194 | + HudiDirectoryLister directoryLister = new HudiDirectoryLister(hadoopConf, session, mockTable); |
| 195 | + HoodieTableMetaClient metaClient = directoryLister.getMetaClient(); |
| 196 | + assertEquals(metaClient.getBasePath(), mockTable.getStorage().getLocation()); |
| 197 | + Path path = new Path(mockTable.getStorage().getLocation(), "p1"); |
| 198 | + ExtendedFileSystem fs = (ExtendedFileSystem) path.getFileSystem(hadoopConf); |
| 199 | + Iterator<HiveFileInfo> fileInfoIterator = directoryLister.list(fs, mockTable, path, Optional.empty(), new NamenodeStats(), new HiveDirectoryContext( |
| 200 | + IGNORED, |
| 201 | + false, |
| 202 | + false, |
| 203 | + new ConnectorIdentity("test", Optional.empty(), Optional.empty()), |
| 204 | + ImmutableMap.of(), |
| 205 | + new RuntimeStats())); |
| 206 | + String partition1FileId = "daf69bc6-01c8-4b86-b9ef-d9c036aa5cdc-0"; |
| 207 | + // expected to have the latest base file in p1 as well as older version because the table is not configured to use merged view |
| 208 | + List<HiveFileInfo> fileInfoList = ImmutableList.copyOf(fileInfoIterator); |
| 209 | + assertEquals(fileInfoList.size(), 1); |
| 210 | + assertTrue(fileInfoList.get(0).getFileName().startsWith(partition1FileId)); |
| 211 | + |
| 212 | + Path path2 = new Path(mockTable.getStorage().getLocation(), "p2"); |
| 213 | + fileInfoIterator = directoryLister.list(fs, mockTable, path2, Optional.empty(), new NamenodeStats(), new HiveDirectoryContext( |
| 214 | + IGNORED, |
| 215 | + false, |
| 216 | + false, |
| 217 | + new ConnectorIdentity("test", Optional.empty(), Optional.empty()), |
| 218 | + ImmutableMap.of(), |
| 219 | + new RuntimeStats())); |
| 220 | + String partition2FileId = "bb70e1e1-8310-4ebe-8a9c-c955f8e72830-0"; |
| 221 | + // expected to have only the latest base file in p2 |
| 222 | + List<HiveFileInfo> fileInfoList2 = ImmutableList.copyOf(fileInfoIterator); |
| 223 | + assertEquals(fileInfoList2.size(), 1); |
| 224 | + assertTrue(fileInfoList2.get(0).getFileName().startsWith(partition2FileId)); |
| 225 | + } |
| 226 | + finally { |
| 227 | + hadoopConf = null; |
| 228 | + } |
| 229 | + } |
| 230 | + |
110 | 231 | @Test
|
111 | 232 | public void testDirectoryListerForHudiTable()
|
112 | 233 | throws IOException
|
|
0 commit comments