carloea2 commented on code in PR #8512: URL: https://github.com/apache/texera/pull/8512#discussion_r4066223859
########## common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/source/scan/parquet/ParquetScanSourceOpDesc.scala: ########## @@ -0,0 +1,154 @@ +/* + * 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 com.fasterxml.jackson.annotation.JsonIgnoreProperties +import org.apache.parquet.hadoop.ParquetFileReader +import org.apache.parquet.io.LocalInputFile +import org.apache.texera.amber.core.executor.OpExecWithClassName +import org.apache.texera.amber.core.storage.DocumentFactory +import org.apache.texera.amber.core.tuple.Schema +import org.apache.texera.amber.core.virtualidentity.{ExecutionIdentity, WorkflowIdentity} +import org.apache.texera.amber.core.workflow.{PhysicalOp, SchemaPropagationFunc} +import org.apache.texera.amber.operator.StandaloneCodeGenerator +import org.apache.texera.amber.operator.StandaloneCodeGenerator.SourceFilePlaceholder +import org.apache.texera.amber.operator.source.scan.ScanSourceOpDesc +import org.apache.texera.amber.util.JSONUtils.objectMapper + +import java.io.IOException +import java.net.URI +import scala.util.Using + +/** + * Reads a Parquet file. The format states its own column types in a footer, so + * unlike the CSV and JSONL sources this one infers nothing: the INTEGER the + * file was written with is the INTEGER that arrives. + */ +@JsonIgnoreProperties(value = Array("fileEncoding")) +class ParquetScanSourceOpDesc extends ScanSourceOpDesc with StandaloneCodeGenerator { + + fileTypeName = Option("Parquet") + + // A DECIMAL is the one column pandas does not land on the same type as the + // executor: it fills that column with decimal.Decimal objects, which a script + // cannot then multiply by a float. + override def standaloneImports(): Seq[String] = Seq("from decimal import Decimal") + + override def standaloneSourcePath(): Option[String] = fileName + + override def generateStandaloneCode(): String = { + // No date columns to name, and no dtype map. pandas reads the types out of + // the same footer the executor does, which is the whole point of the format; + // the text formats have to be told because they carry nothing to read. + // Read into the nullable dtypes, as the Arrow source is. Parquet says of + // every value whether it is there, and a numpy column has nowhere to put + // that: pandas widens a holed integer column through a float, where every + // value past 2^53 is rounded and 9007199254740993 came back as ...992. The + // executor reads the exact long, and the declared column stays integral. + val read = + s"""out1df = pd.read_parquet($SourceFilePlaceholder, dtype_backend="numpy_nullable")""" Review Comment: Retested fcd65b6a9. The named customer_id column is preserved with values 101 and 102. This finding is fixed. -- 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]
