forked from NVIDIA/spark-rapids
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert ":Revert "Improve dateFormat support in GpuJsonScan and make t…
…ests consistent with GpuStructsToJson [databricks] (NVIDIA#9975)"" This reverts commit 90a7dca.
- Loading branch information
Showing
9 changed files
with
391 additions
and
156 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
99 changes: 99 additions & 0 deletions
99
sql-plugin/src/main/spark320/scala/com/nvidia/spark/rapids/shims/GpuJsonToStructsShim.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,99 @@ | ||
/* | ||
* Copyright (c) 2024, NVIDIA CORPORATION. | ||
* | ||
* 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. | ||
*/ | ||
/*** spark-rapids-shim-json-lines | ||
{"spark": "320"} | ||
{"spark": "321"} | ||
{"spark": "321cdh"} | ||
{"spark": "321db"} | ||
{"spark": "322"} | ||
{"spark": "323"} | ||
{"spark": "324"} | ||
{"spark": "330"} | ||
{"spark": "330cdh"} | ||
{"spark": "330db"} | ||
{"spark": "331"} | ||
{"spark": "332"} | ||
{"spark": "332cdh"} | ||
{"spark": "332db"} | ||
{"spark": "333"} | ||
{"spark": "334"} | ||
spark-rapids-shim-json-lines ***/ | ||
package com.nvidia.spark.rapids.shims | ||
|
||
import ai.rapids.cudf.{ColumnVector, DType, Scalar} | ||
import com.nvidia.spark.rapids.{DateUtils, GpuCast, GpuOverrides, RapidsMeta} | ||
import com.nvidia.spark.rapids.Arm.withResource | ||
|
||
import org.apache.spark.sql.rapids.ExceptionTimeParserPolicy | ||
|
||
object GpuJsonToStructsShim { | ||
|
||
def tagDateFormatSupport(meta: RapidsMeta[_, _, _], dateFormat: Option[String]): Unit = { | ||
// dateFormat is ignored by JsonToStructs in Spark 3.2.x and 3.3.x because it just | ||
// performs a regular cast from string to date | ||
} | ||
|
||
def castJsonStringToDate(input: ColumnVector, options: Map[String, String]): ColumnVector = { | ||
// dateFormat is ignored in from_json in Spark 3.2 | ||
withResource(Scalar.fromString(" ")) { space => | ||
withResource(input.strip(space)) { trimmed => | ||
GpuCast.castStringToDate(trimmed) | ||
} | ||
} | ||
} | ||
|
||
def tagDateFormatSupportFromScan(meta: RapidsMeta[_, _, _], dateFormat: Option[String]): Unit = { | ||
} | ||
|
||
def castJsonStringToDateFromScan(input: ColumnVector, dt: DType, | ||
dateFormat: Option[String]): ColumnVector = { | ||
dateFormat match { | ||
case None => | ||
// legacy behavior | ||
withResource(input.strip()) { trimmed => | ||
GpuCast.castStringToDateAnsi(trimmed, ansiMode = | ||
GpuOverrides.getTimeParserPolicy == ExceptionTimeParserPolicy) | ||
} | ||
case Some(fmt) => | ||
withResource(input.strip()) { trimmed => | ||
val regexRoot = fmt | ||
.replace("yyyy", raw"\d{4}") | ||
.replace("MM", raw"\d{1,2}") | ||
.replace("dd", raw"\d{1,2}") | ||
val cudfFormat = DateUtils.toStrf(fmt, parseString = true) | ||
GpuCast.convertDateOrNull(trimmed, "^" + regexRoot + "$", cudfFormat, | ||
failOnInvalid = GpuOverrides.getTimeParserPolicy == ExceptionTimeParserPolicy) | ||
} | ||
} | ||
} | ||
|
||
def tagTimestampFormatSupport(meta: RapidsMeta[_, _, _], | ||
timestampFormat: Option[String]): Unit = { | ||
// we only support the case where no format is specified | ||
timestampFormat.foreach(f => meta.willNotWorkOnGpu(s"Unsupported timestampFormat: $f")) | ||
} | ||
|
||
def castJsonStringToTimestamp(input: ColumnVector, | ||
options: Map[String, String]): ColumnVector = { | ||
// legacy behavior | ||
withResource(Scalar.fromString(" ")) { space => | ||
withResource(input.strip(space)) { trimmed => | ||
// from_json doesn't respect ansi mode | ||
GpuCast.castStringToTimestamp(trimmed, ansiMode = false) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.