carloea2 commented on code in PR #8512:
URL: https://github.com/apache/texera/pull/8512#discussion_r4001987571


##########
common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/source/scan/parquet/ParquetSchemaMapping.scala:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.texera.amber.operator.source.scan.parquet
+
+import org.apache.parquet.schema.LogicalTypeAnnotation
+import org.apache.parquet.schema.LogicalTypeAnnotation.{
+  DateLogicalTypeAnnotation,
+  StringLogicalTypeAnnotation,
+  TimestampLogicalTypeAnnotation
+}
+import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName
+import org.apache.parquet.schema.{MessageType, PrimitiveType, Type}
+import org.apache.texera.amber.core.tuple.{Attribute, AttributeType, Schema}
+
+import scala.jdk.CollectionConverters._
+
+/**
+  * What a Parquet file says its columns are, in Texera's terms.
+  *
+  * The file states its own types, so nothing is inferred from the values the 
way
+  * a CSV forces. Only the flat primitives map: a column that is a group, a 
list
+  * or a map has no Texera column to be, and is refused by name rather than
+  * silently dropped or stringified.
+  */
+object ParquetSchemaMapping {
+
+  /** Texera's reading of the file's own schema, in the file's column order. */
+  def toTexeraSchema(messageType: MessageType): Schema =
+    new Schema(
+      messageType.getFields.asScala.toSeq
+        .map(field => new Attribute(field.getName, typeOf(field))): _*
+    )
+
+  /** The Texera type a Parquet column is read as, or an error naming the 
column. */
+  def typeOf(field: Type): AttributeType = {
+    if (!field.isPrimitive) {
+      throw new UnsupportedOperationException(
+        s"Parquet column '${field.getName}' is a nested ${describe(field)}, 
which has no Texera " +
+          "column to be. Flatten it before reading the file."
+      )
+    }
+    val primitive = field.asPrimitiveType()
+    primitive.getPrimitiveTypeName match {
+      case PrimitiveTypeName.BOOLEAN                          => 
AttributeType.BOOLEAN
+      case PrimitiveTypeName.FLOAT | PrimitiveTypeName.DOUBLE => 
AttributeType.DOUBLE
+      case PrimitiveTypeName.INT32 =>
+        annotated[DateLogicalTypeAnnotation](
+          primitive,
+          AttributeType.TIMESTAMP,
+          AttributeType.INTEGER

Review Comment:
   Retested 04036a0 with the same Parquet files. The decimal and microsecond 
regressions now pass, along with the whole-millisecond control.



-- 
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]

Reply via email to