-
Notifications
You must be signed in to change notification settings - Fork 29.2k
[SPARK-57101][SQL] Register nanosecond timestamp types in the Types Framework (server-side) #56199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MaxGekk
wants to merge
12
commits into
apache:master
Choose a base branch
from
MaxGekk:nanos-type-framework
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e56648d
[SPARK-57101][SQL] Register nanosecond timestamp types in the Types F…
MaxGekk b45b845
[SPARK-57101][SQL] Wire Literal.doGenCode to use TypeOps.getJavaLiter…
MaxGekk 2425517
[SPARK-57101][SQL] Pin full toSQLValue output in TimestampNanosTypeOp…
MaxGekk 891736c
[SPARK-57101][SQL] Add direct test for MutableTimestampNanos.copy()
MaxGekk 8b2ac7b
[SPARK-57101][SQL] Bump @since tags from 4.2.0 to 4.3.0 in nanos Type…
MaxGekk 96b7f73
[SPARK-57101][SQL] Register nanosecond timestamp types in the Types F…
MaxGekk 52850ae
[SPARK-57101][SQL] Reformat TimestampNanosTypeApiOps.scala with scalafmt
MaxGekk b55262f
[SPARK-57101][SQL] Bump @since tags from 4.2.0 to 4.3.0 in nanos Type…
MaxGekk 2cb3993
[SPARK-57101][SQL] Fix fatal Javadoc errors in TimestampNanosTypeApiOps
MaxGekk 6809f1e
[SPARK-57101][SQL] Route TimeType literals through TypeOps.getJavaLit…
MaxGekk 6649226
[SPARK-57101][SQL] Route getValue/setColumn through TypeOps before is…
MaxGekk e932e50
[SPARK-57101][SQL] Fix import ordering in TimestampNanosTypeOpsSuite …
MaxGekk 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
85 changes: 85 additions & 0 deletions
85
sql/api/src/main/scala/org/apache/spark/sql/types/ops/TimestampNanosTypeApiOps.scala
This file contains hidden or 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,85 @@ | ||
| /* | ||
| * 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.spark.sql.types.ops | ||
|
|
||
| import org.apache.spark.sql.AnalysisException | ||
| import org.apache.spark.sql.catalyst.encoders.AgnosticEncoder | ||
| import org.apache.spark.sql.errors.DataTypeErrorsBase | ||
| import org.apache.spark.sql.types.{TimestampLTZNanosType, TimestampNTZNanosType} | ||
| import org.apache.spark.unsafe.types.TimestampNanosVal | ||
|
|
||
| /** | ||
| * Client-side (spark-api) operations shared by the nanosecond timestamp types | ||
| * (TimestampNTZNanosType and TimestampLTZNanosType). | ||
| * | ||
| * Internal values are [[org.apache.spark.unsafe.types.TimestampNanosVal]] (epoch micros + nanos | ||
| * within the micro). The two concrete subclasses differ only in their DataType and SQL-literal | ||
| * prefix; storage and formatting are identical. | ||
| * | ||
| * SCOPE (SPARK-57101): this issue wires physical representation, literals, row accessors, and | ||
| * codegen class selection. String formatting here is an interim implementation until dedicated | ||
| * fractional-second formatters land in a follow-up issue; Dataset encoders are out of scope | ||
| * (SPARK-57033 and related), so getEncoder reports the type as unsupported, matching the legacy | ||
| * RowEncoder behavior. | ||
| * | ||
| * @since 4.3.0 | ||
| */ | ||
| abstract class TimestampNanosTypeApiOps extends TypeApiOps with DataTypeErrorsBase { | ||
|
|
||
| /** SQL literal prefix for this type, e.g. "TIMESTAMP_NTZ" or "TIMESTAMP_LTZ". */ | ||
| protected def sqlTypeName: String | ||
|
|
||
| // ==================== String Formatting (interim) ==================== | ||
|
|
||
| override def format(v: Any): String = v.asInstanceOf[TimestampNanosVal].toString | ||
|
|
||
| override def toSQLValue(v: Any): String = s"$sqlTypeName '${format(v)}'" | ||
|
|
||
| // ==================== Row Encoding ==================== | ||
|
|
||
| // Encoders are handled in a follow-up issue (SPARK-57033). Until then, report the type as | ||
| // unsupported with the same error as the legacy RowEncoder fallback to preserve parity. | ||
| override def getEncoder: AgnosticEncoder[_] = | ||
| throw new AnalysisException( | ||
| errorClass = "UNSUPPORTED_DATA_TYPE_FOR_ENCODER", | ||
| messageParameters = Map("dataType" -> toSQLType(dataType))) | ||
| } | ||
|
|
||
| /** | ||
| * Client-side operations for [[org.apache.spark.sql.types.TimestampNTZNanosType]]. | ||
| * | ||
| * @param t | ||
| * The TimestampNTZNanosType with precision information | ||
| * @since 4.3.0 | ||
| */ | ||
| class TimestampNTZNanosTypeApiOps(val t: TimestampNTZNanosType) extends TimestampNanosTypeApiOps { | ||
| override def dataType: TimestampNTZNanosType = t | ||
| override protected def sqlTypeName: String = "TIMESTAMP_NTZ" | ||
| } | ||
|
|
||
| /** | ||
| * Client-side operations for [[org.apache.spark.sql.types.TimestampLTZNanosType]]. | ||
| * | ||
| * @param t | ||
| * The TimestampLTZNanosType with precision information | ||
| * @since 4.3.0 | ||
| */ | ||
| class TimestampLTZNanosTypeApiOps(val t: TimestampLTZNanosType) extends TimestampNanosTypeApiOps { | ||
| override def dataType: TimestampLTZNanosType = t | ||
| override protected def sqlTypeName: String = "TIMESTAMP_LTZ" | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
We will replace this after the PR #56158 is merged.