-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* build: Add Spark 3.3.0 * build: Add Spark 3.3 * make it compile for 3.3 will fail on all other 3.x * try to make it compile * try to make it compile * try to make it compile * try to make it compile * try to make it compile * compiles with sbt for all versions, some unit test with 3.3.0 still fail but most is good * build: Add Spark 3.3.0 * build: Add Spark 3.3 * make it compile for 3.3 will fail on all other 3.x * try to make it compile * try to make it compile * try to make it compile * try to make it compile * try to make it compile * compiles with sbt for all versions, some unit test with 3.3.0 still fail but most is good * use spark 3.3.1 instead of 3.3.0, log4j props for log4j 1 and 2, removed change in WorkbookReader * build.sbt, added log4j handling for earlier versions than 3.3.x * fixed locale issue * merged main including module rename * license got lost * reorg folders * reorg folders incl. mill * fixed log4j in mill * fixed log4j in mill * fixed log4j in mill Co-authored-by: Martin Mauch <martin.mauch@gmail.com>
- Loading branch information
1 parent
79e398e
commit db65e19
Showing
17 changed files
with
240 additions
and
44 deletions.
There are no files selected for viewing
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
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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
107 changes: 107 additions & 0 deletions
107
src/main/3.3/scala/com/crealytics/spark/excel/v2/ExcelScan.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,107 @@ | ||
/* | ||
* Copyright 2022 Martin Mauch (@nightscape) | ||
* | ||
* Licensed 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.crealytics.spark.excel.v2 | ||
|
||
import org.apache.hadoop.fs.Path | ||
import org.apache.spark.sql.SparkSession | ||
import org.apache.spark.sql.catalyst.expressions.{ExprUtils, Expression} | ||
import org.apache.spark.sql.connector.read.PartitionReaderFactory | ||
import org.apache.spark.sql.execution.datasources.PartitioningAwareFileIndex | ||
import org.apache.spark.sql.execution.datasources.v2.TextBasedFileScan | ||
import org.apache.spark.sql.sources.Filter | ||
import org.apache.spark.sql.types.StructType | ||
import org.apache.spark.sql.util.CaseInsensitiveStringMap | ||
import org.apache.spark.util.SerializableConfiguration | ||
|
||
import scala.collection.compat.immutable.ArraySeq | ||
import scala.jdk.CollectionConverters._ | ||
|
||
case class ExcelScan( | ||
sparkSession: SparkSession, | ||
fileIndex: PartitioningAwareFileIndex, | ||
dataSchema: StructType, | ||
readDataSchema: StructType, | ||
readPartitionSchema: StructType, | ||
options: CaseInsensitiveStringMap, | ||
pushedFilters: Array[Filter], | ||
partitionFilters: Seq[Expression] = Seq.empty, | ||
dataFilters: Seq[Expression] = Seq.empty | ||
) extends TextBasedFileScan(sparkSession, options) { | ||
|
||
private lazy val parsedOptions: ExcelOptions = new ExcelOptions( | ||
options.asScala.toMap, | ||
sparkSession.sessionState.conf.sessionLocalTimeZone, | ||
sparkSession.sessionState.conf.columnNameOfCorruptRecord | ||
) | ||
|
||
override def isSplitable(path: Path): Boolean = false | ||
|
||
override def getFileUnSplittableReason(path: Path): String = { | ||
"No practical method of splitting an excel file" | ||
} | ||
|
||
override def createReaderFactory(): PartitionReaderFactory = { | ||
|
||
/* Check a field requirement for corrupt records here to throw an exception in a driver side | ||
*/ | ||
ExprUtils.verifyColumnNameOfCorruptRecord(dataSchema, parsedOptions.columnNameOfCorruptRecord) | ||
|
||
if ( | ||
readDataSchema.length == 1 && | ||
readDataSchema.head.name == parsedOptions.columnNameOfCorruptRecord | ||
) { | ||
throw new RuntimeException( | ||
"Queries from raw Excel files are disallowed when the referenced " + | ||
"columns only include the internal corrupt record column" | ||
) | ||
} | ||
|
||
val caseSensitiveMap = options.asCaseSensitiveMap.asScala.toMap | ||
|
||
/* Hadoop Configurations are case sensitive. */ | ||
val hadoopConf = sparkSession.sessionState.newHadoopConfWithOptions(caseSensitiveMap) | ||
|
||
val broadcastedConf = sparkSession.sparkContext | ||
.broadcast(new SerializableConfiguration(hadoopConf)) | ||
|
||
/* The partition values are already truncated in `FileScan.partitions`. We should use `readPartitionSchema` as the | ||
* partition schema here. | ||
*/ | ||
ExcelPartitionReaderFactory( | ||
sparkSession.sessionState.conf, | ||
broadcastedConf, | ||
dataSchema, | ||
readDataSchema, | ||
readPartitionSchema, | ||
parsedOptions, | ||
ArraySeq.unsafeWrapArray(pushedFilters) | ||
) | ||
} | ||
|
||
override def equals(obj: Any): Boolean = obj match { | ||
case c: ExcelScan => | ||
super.equals(c) && dataSchema == c.dataSchema && options == c.options && | ||
equivalentFilters(pushedFilters, c.pushedFilters) | ||
case _ => false | ||
} | ||
|
||
override def hashCode(): Int = super.hashCode() | ||
|
||
override def description(): String = { | ||
super.description() + ", PushedFilters: " + pushedFilters.mkString("[", ", ", "]") | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/3.3/scala/com/crealytics/spark/excel/v2/ExcelScanBuilder.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,40 @@ | ||
/* | ||
* Copyright 2022 Martin Mauch (@nightscape) | ||
* | ||
* Licensed 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.crealytics.spark.excel.v2 | ||
|
||
import org.apache.spark.sql.SparkSession | ||
import org.apache.spark.sql.connector.read.Scan | ||
import org.apache.spark.sql.execution.datasources.PartitioningAwareFileIndex | ||
import org.apache.spark.sql.execution.datasources.v2.FileScanBuilder | ||
import org.apache.spark.sql.internal.connector.SupportsPushDownCatalystFilters | ||
import org.apache.spark.sql.types.StructType | ||
import org.apache.spark.sql.util.CaseInsensitiveStringMap | ||
|
||
case class ExcelScanBuilder( | ||
sparkSession: SparkSession, | ||
fileIndex: PartitioningAwareFileIndex, | ||
schema: StructType, | ||
dataSchema: StructType, | ||
options: CaseInsensitiveStringMap | ||
) extends FileScanBuilder(sparkSession, fileIndex, dataSchema) | ||
with SupportsPushDownCatalystFilters { | ||
|
||
override def build(): Scan = { | ||
ExcelScan(sparkSession, fileIndex, dataSchema, readDataSchema(), readPartitionSchema(), options, pushedDataFilters) | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,5 +1,23 @@ | ||
# config for log4j 1.x (spark < 3.3) | ||
log4j.rootCategory=ERROR, console | ||
log4j.appender.console=org.apache.log4j.ConsoleAppender | ||
log4j.appender.console.target=System.out | ||
log4j.appender.console.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{1}: %m%n | ||
|
||
# config for log4j 2.x (spark >= 3.3) | ||
# Extra logging related to initialization of Log4j | ||
# Set to debug or trace if log4j initialization is failing | ||
status = warn | ||
|
||
|
||
# Console appender configuration | ||
appender.console.type = Console | ||
appender.console.name = consoleLogger | ||
appender.console.layout.type = PatternLayout | ||
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n | ||
|
||
# Root logger level | ||
rootLogger.level = debug | ||
# Root logger referring to console appender | ||
rootLogger.appenderRef.stdout.ref = consoleLogger |