RussellSpitzer commented on a change in pull request #3723:
URL: https://github.com/apache/iceberg/pull/3723#discussion_r771552852



##########
File path: 
spark/v3.2/spark/src/test/java/org/apache/iceberg/spark/data/TestParquetReader.java
##########
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iceberg.spark.data;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.spark.SparkSessionCatalog;
+import org.apache.iceberg.spark.SparkTestBaseWithCatalog;
+import org.apache.iceberg.spark.actions.SparkActions;
+import org.apache.spark.sql.SparkSession;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+public class TestParquetReader extends SparkTestBaseWithCatalog {
+  private static SparkSession spark = null;
+  private static String catalogName = "spark_catalog";
+  private static String implementation = SparkSessionCatalog.class.getName();
+  private static Map<String, String> config = ImmutableMap.of(
+      "type", "hive",
+      "default-namespace", "default",
+      "parquet-enabled", "true",
+      "cache-enabled", "false"
+  );
+
+  @Rule
+  public TemporaryFolder temp = new TemporaryFolder();
+
+  public TestParquetReader() {
+    super(catalogName, implementation, config);
+    spark.sessionState().catalogManager().catalog(catalogName);
+  }
+
+  @BeforeClass
+  public static void startSpark() {
+    TestParquetReader.spark = SparkSession.builder().master("local[2]")
+            .config("spark.sql.parquet.writeLegacyFormat", true)
+            .getOrCreate();
+    spark.sessionState().catalogManager().catalog("spark_catalog");
+  }
+
+  @AfterClass
+  public static void stopSpark() {
+    SparkSession currentSpark = TestParquetReader.spark;
+    TestParquetReader.spark = null;
+    currentSpark.stop();
+  }
+
+  @Test

Review comment:
       I thought a bit about how to trick Spark into using the Old Map Red 
style serde. This is a little difficult because spark checks to see if 
"parquet" is in the name of the serde and then just uses it's own if it sees 
that.
   
   So step 1 Make a fake Serde that is the mapred parquet serde but isn't named 
that
   ```
   import org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe;
   import org.apache.hadoop.hive.serde.serdeConstants;
   import org.apache.hadoop.hive.serde2.SerDeSpec;
   import org.apache.parquet.hadoop.ParquetOutputFormat;
   
   @SerDeSpec(schemaProps = {serdeConstants.LIST_COLUMNS, 
serdeConstants.LIST_COLUMN_TYPES,
       ParquetOutputFormat.COMPRESSION})
   public class OldParSerde extends ParquetHiveSerDe {
   
   }
   ```
   
   Step 2 : Create and write to our new table using the old SERDE, *then* 
switch it back to the normal parquet one. This is important because Iceberg 
needs "parquet" to be in the format for migrate to work
   ```java
       File location = temp.newFolder();
       // Create the table using 
       sql("CREATE TABLE %s (col1 ARRAY<STRUCT<col2 INT>>)" +
           " ROW FORMAT SERDE '%s'" +
           "  STORED AS INPUTFORMAT" +
           " 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat'" +
           "  OUTPUTFORMAT" +
           " 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'" +
           " LOCATION '%s'", tableName, OldParSerde.class.getName(), location);
   
       int testValue = 12345;
       sql(String.format("INSERT INTO %s VALUES (ARRAY(STRUCT(%s)))", 
tableName, testValue));
       List<Object[]> expected = sql(String.format("SELECT * FROM %s", 
tableName));
   
       sql("ALTER TABLE %s SET SERDE '%s'", tableName, 
ParquetHiveSerDe.class.getName());
   ```
   
   Step 3: Migrate the now normal hive table
   ```java
    // migrate table
       SparkActions.get().migrateTable(tableName).execute();
   
       // check migrated table is returning expected result
       List<Object[]> results = sql(String.format("SELECT * FROM %s", 
tableName));
       Assert.assertTrue(results.size() > 0);
       assertEquals("Output must match", expected, results);
   ```
   
   Output :
   ```
   java.lang.AssertionError: Output must match: row 1 col 1 contents should 
match expected:<[[12345]]> but was:<null>
        at org.junit.Assert.fail(Assert.java:89)
   ```
   
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to