|
29 | 29 | import org.testng.annotations.DataProvider;
|
30 | 30 | import org.testng.annotations.Test;
|
31 | 31 |
|
| 32 | +import java.io.IOException; |
32 | 33 | import java.nio.file.Path;
|
33 | 34 | import java.util.function.BiConsumer;
|
34 | 35 | import java.util.regex.Matcher;
|
|
47 | 48 | import static com.google.common.base.Preconditions.checkArgument;
|
48 | 49 | import static com.google.common.collect.Iterables.getOnlyElement;
|
49 | 50 | import static java.lang.String.format;
|
| 51 | +import static java.nio.file.Files.createTempDirectory; |
50 | 52 | import static java.util.Locale.ENGLISH;
|
51 | 53 | import static java.util.Objects.requireNonNull;
|
52 | 54 | import static java.util.stream.Collectors.joining;
|
@@ -152,6 +154,91 @@ public void testShowCreateTable()
|
152 | 154 | ")", schemaName, getLocation(schemaName, "orders")));
|
153 | 155 | }
|
154 | 156 |
|
| 157 | + @Test |
| 158 | + public void testTableWithSpecifiedWriteDataLocation() |
| 159 | + throws IOException |
| 160 | + { |
| 161 | + String tableName = "test_table_with_specified_write_data_location"; |
| 162 | + String dataWriteLocation = createTempDirectory(tableName).toAbsolutePath().toString(); |
| 163 | + try { |
| 164 | + assertUpdate(format("create table %s(a int, b varchar) with (\"write.data.path\" = '%s')", tableName, dataWriteLocation)); |
| 165 | + assertUpdate(format("insert into %s values(1, '1001'), (2, '1002'), (3, '1003')", tableName), 3); |
| 166 | + assertQuery("select * from " + tableName, "values(1, '1001'), (2, '1002'), (3, '1003')"); |
| 167 | + assertUpdate(format("delete from %s where a > 2", tableName), 1); |
| 168 | + assertQuery("select * from " + tableName, "values(1, '1001'), (2, '1002')"); |
| 169 | + } |
| 170 | + finally { |
| 171 | + try { |
| 172 | + getQueryRunner().execute("drop table if exists " + tableName); |
| 173 | + } |
| 174 | + catch (Exception e) { |
| 175 | + // ignored for hive catalog compatibility |
| 176 | + } |
| 177 | + } |
| 178 | + } |
| 179 | + |
| 180 | + @Test |
| 181 | + public void testPartitionedTableWithSpecifiedWriteDataLocation() |
| 182 | + throws IOException |
| 183 | + { |
| 184 | + String tableName = "test_partitioned_table_with_specified_write_data_location"; |
| 185 | + String dataWriteLocation = createTempDirectory(tableName).toAbsolutePath().toString(); |
| 186 | + try { |
| 187 | + assertUpdate(format("create table %s(a int, b varchar) with (partitioning = ARRAY['a'], \"write.data.path\" = '%s')", tableName, dataWriteLocation)); |
| 188 | + assertUpdate(format("insert into %s values(1, '1001'), (2, '1002'), (3, '1003')", tableName), 3); |
| 189 | + assertQuery("select * from " + tableName, "values(1, '1001'), (2, '1002'), (3, '1003')"); |
| 190 | + assertUpdate(format("delete from %s where a > 2", tableName), 1); |
| 191 | + assertQuery("select * from " + tableName, "values(1, '1001'), (2, '1002')"); |
| 192 | + } |
| 193 | + finally { |
| 194 | + try { |
| 195 | + getQueryRunner().execute("drop table if exists " + tableName); |
| 196 | + } |
| 197 | + catch (Exception e) { |
| 198 | + // ignored for hive catalog compatibility |
| 199 | + } |
| 200 | + } |
| 201 | + } |
| 202 | + |
| 203 | + @Test |
| 204 | + public void testShowCreateTableWithSpecifiedWriteDataLocation() |
| 205 | + throws IOException |
| 206 | + { |
| 207 | + String tableName = "test_show_table_with_specified_write_data_location"; |
| 208 | + String dataWriteLocation = createTempDirectory("test1").toAbsolutePath().toString(); |
| 209 | + try { |
| 210 | + assertUpdate(format("CREATE TABLE %s(a int, b varchar) with (\"write.data.path\" = '%s')", tableName, dataWriteLocation)); |
| 211 | + String schemaName = getSession().getSchema().get(); |
| 212 | + String location = getLocation(schemaName, tableName); |
| 213 | + String createTableSql = "CREATE TABLE iceberg.%s.%s (\n" + |
| 214 | + " \"a\" integer,\n" + |
| 215 | + " \"b\" varchar\n" + |
| 216 | + ")\n" + |
| 217 | + "WITH (\n" + |
| 218 | + " delete_mode = 'merge-on-read',\n" + |
| 219 | + " format = 'PARQUET',\n" + |
| 220 | + " format_version = '2',\n" + |
| 221 | + " location = '%s',\n" + |
| 222 | + " metadata_delete_after_commit = false,\n" + |
| 223 | + " metadata_previous_versions_max = 100,\n" + |
| 224 | + " metrics_max_inferred_column = 100,\n" + |
| 225 | + " \"read.split.target-size\" = 134217728,\n" + |
| 226 | + " \"write.data.path\" = '%s',\n" + |
| 227 | + " \"write.update.mode\" = 'merge-on-read'\n" + |
| 228 | + ")"; |
| 229 | + assertThat(computeActual("SHOW CREATE TABLE " + tableName).getOnlyValue()) |
| 230 | + .isEqualTo(format(createTableSql, schemaName, tableName, location, dataWriteLocation)); |
| 231 | + } |
| 232 | + finally { |
| 233 | + try { |
| 234 | + getQueryRunner().execute("DROP TABLE IF EXISTS " + tableName); |
| 235 | + } |
| 236 | + catch (Exception e) { |
| 237 | + // ignored for hive catalog compatibility |
| 238 | + } |
| 239 | + } |
| 240 | + } |
| 241 | + |
155 | 242 | @Test
|
156 | 243 | public void testDecimal()
|
157 | 244 | {
|
|
0 commit comments