This repository has been archived by the owner on Sep 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
[NSE-1161] Support read-write parquet conversion to read-write arrow #1162
Merged
zhouyuan
merged 6 commits into
oap-project:main
from
jackylee-ch:add_arrow_read_write_convertion
Dec 6, 2022
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bea7813
add ArrowConvertExtension
jackylee-ch 3d35855
do not convert parquet fileformat while writing to partitioned/bucket…
jackylee-ch 63b41a8
fix cache failed
jackylee-ch 8c788f7
care about write codec
jackylee-ch a3623c2
disable convertor extension by default
jackylee-ch 16298f1
add some comments
jackylee-ch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
...w-data-source/standard/src/main/scala/com/intel/oap/spark/sql/ArrowConvertExtension.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* 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 com.intel.oap.spark.sql | ||
|
||
import java.util.Locale | ||
|
||
import com.intel.oap.spark.sql.execution.datasources.arrow.ArrowFileFormat | ||
import org.apache.parquet.hadoop.ParquetOutputFormat | ||
|
||
import org.apache.spark.sql.{SparkSession, SparkSessionExtensions} | ||
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan | ||
import org.apache.spark.sql.catalyst.rules.Rule | ||
import org.apache.spark.sql.execution.command.InsertIntoDataSourceDirCommand | ||
import org.apache.spark.sql.execution.datasources.{HadoopFsRelation, InsertIntoHadoopFsRelationCommand, LogicalRelation} | ||
import org.apache.spark.sql.execution.datasources.parquet.ParquetFileFormat | ||
|
||
class ArrowConvertorExtension extends (SparkSessionExtensions => Unit) { | ||
def apply(e: SparkSessionExtensions): Unit = { | ||
e.injectPostHocResolutionRule(session => ArrowConvertorRule(session)) | ||
} | ||
} | ||
|
||
case class ArrowConvertorRule(session: SparkSession) extends Rule[LogicalPlan] { | ||
override def apply(plan: LogicalPlan): LogicalPlan = { | ||
plan resolveOperators { | ||
// Write datasource path | ||
// TODO: support writing with partitioned/bucketed/sorted column | ||
case c: InsertIntoHadoopFsRelationCommand | ||
if c.fileFormat.isInstanceOf[ParquetFileFormat] && | ||
c.partitionColumns.isEmpty && c.bucketSpec.isEmpty => | ||
// TODO: Support pass parquet config and writing with other codecs | ||
// `compression`, `parquet.compression`(i.e., ParquetOutputFormat.COMPRESSION), and | ||
// `spark.sql.parquet.compression.codec` | ||
// are in order of precedence from highest to lowest. | ||
val parquetCompressionConf = c.options.get(ParquetOutputFormat.COMPRESSION) | ||
val codecName = c.options | ||
.get("compression") | ||
.orElse(parquetCompressionConf) | ||
.getOrElse(session.sessionState.conf.parquetCompressionCodec) | ||
.toLowerCase(Locale.ROOT) | ||
if (codecName.equalsIgnoreCase("snappy")) { | ||
c.copy(fileFormat = new ArrowFileFormat) | ||
} else { | ||
c | ||
} | ||
|
||
// Read path | ||
case l@ LogicalRelation( | ||
r@ HadoopFsRelation(_, _, _, _, _: ParquetFileFormat, _), _, _, _) => | ||
l.copy(relation = r.copy(fileFormat = new ArrowFileFormat)(session)) | ||
|
||
// INSERT DIR | ||
case c: InsertIntoDataSourceDirCommand if c.provider == "parquet" => | ||
c.copy(provider = "arrow") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compresssion is supported in this pr. Maybe merge this pr first, then I can remove these codes?
#1014
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, thanks