Skip to content

Commit 6ab4a64

Browse files
authored
[SPARK] Test parquet table creation by Spark 3.5.3 (unitycatalog#357)
This PR is to test parquet table creation by create table or create table select as
1 parent 842ee33 commit 6ab4a64

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

connectors/spark/src/test/java/io/unitycatalog/spark/TableReadWriteTest.java

+27-12
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,33 @@ private void setupExternalDeltaTable(
264264

265265
@Test
266266
public void testCreateExternalParquetTable() throws ApiException, IOException {
267-
SparkSession session = createSparkSessionWithCatalogs(CATALOG_NAME);
268-
String path = generateTableLocation(CATALOG_NAME, PARQUET_TABLE);
269-
String fullTableName = CATALOG_NAME + "." + SCHEMA_NAME + "." + PARQUET_TABLE;
270-
session
271-
.sql(
272-
"CREATE TABLE " + fullTableName + "(name STRING) USING PARQUET LOCATION '" + path + "'")
273-
.collect();
274-
assertTrue(session.catalog().tableExists(fullTableName));
275-
TableInfo tableInfo = tableOperations.getTable(fullTableName);
276-
assertEquals(1, tableInfo.getColumns().size());
277-
assertEquals("name", tableInfo.getColumns().get(0).getName());
278-
assertEquals(ColumnTypeName.STRING, tableInfo.getColumns().get(0).getTypeName());
267+
268+
SparkSession session = createSparkSessionWithCatalogs(SPARK_CATALOG, CATALOG_NAME);
269+
String[] names = {SPARK_CATALOG, CATALOG_NAME};
270+
for (String testCatalog : names) {
271+
String path = generateTableLocation(testCatalog, PARQUET_TABLE);
272+
String fullTableName = testCatalog + "." + SCHEMA_NAME + "." + PARQUET_TABLE;
273+
String fullTableName2 = testCatalog + "." + SCHEMA_NAME + "." + ANOTHER_PARQUET_TABLE;
274+
275+
session.sql(
276+
"CREATE TABLE "
277+
+ fullTableName
278+
+ " USING parquet LOCATION '"
279+
+ path
280+
+ "' as SELECT 1, 2, 3");
281+
assertThat(session.sql("SELECT * FROM " + fullTableName).collectAsList().size() == 1);
282+
String path2 = generateTableLocation(testCatalog, ANOTHER_PARQUET_TABLE);
283+
session
284+
.sql(
285+
"CREATE TABLE "
286+
+ fullTableName2
287+
+ "(i INT, s STRING) USING PARQUET LOCATION '"
288+
+ path2
289+
+ "'")
290+
.collect();
291+
testTableReadWrite(fullTableName2, session);
292+
}
293+
279294
session.stop();
280295
}
281296

0 commit comments

Comments
 (0)