You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "VandanaSah (via GitHub)" <gi...@apache.org> on 2026/04/19 06:30:02 UTC

[PR] Vandana ibm 3.5.4 [spark]

VandanaSah opened a new pull request, #55411:
URL: https://github.com/apache/spark/pull/55411

   ## 1. Proposed Changes
   
   This PR implements comprehensive support for the SQL `TIME` data type in Apache Spark 3.5.4, adding a new temporal type representing time-of-day values with microsecond precision.
   
   **Core Implementation:**
   - New [`TimeType`](sql/api/src/main/scala/org/apache/spark/sql/types/TimeType.scala) class extending `AtomicType`
   - Internal storage as `LONG` (8 bytes) representing microseconds since midnight (0 to 86,399,999,999)
   - Type name: `"time(6)"` indicating microsecond precision
   - SQL literal syntax: `TIME 'HH:mm:ss[.SSSSSS]'`
   
   **Modified Components :**
   - Core type system: Type definition, registration, physical type mapping
   - SQL parser: TIME literal parsing and DDL support
   - Expression framework: Casting (STRING ↔ TIME, TIMESTAMP ↔ TIME, BIGINT ↔ TIME), comparison, arithmetic
   - File formats: ORC, Parquet, CSV, JSON readers/writers with schema preservation
   - Hive integration: Catalog, client, inspector modifications mapping TIME to BIGINT
   - JDBC/Thrift server: Type mapping to `java.sql.Types.TIME` (92)(the integer 92 is the standard JDBC type code for TIME), metadata support
   - Code generation: Optimized execution paths
   
   ## 2. Why Needed (Motivation)
   
   **SQL Standard Compliance:**
   - Implements SQL:2016 standard TIME type, filling a gap in Spark's temporal type system
   - Enables separation of time-of-day from date information
   
   **Use Cases Enabled:**
   - Event logging systems storing precise event times without date overhead
   - Scheduling applications (business hours, appointments, recurring events)
   - Time series analysis separating time-of-day patterns from date trends
   - Data warehousing with efficient time dimensions
   - Healthcare systems recording medication/treatment schedules
   
   ## 3. User-Facing Changes
   
   **New SQL Syntax:**
   ```sql
   -- TIME literals
   SELECT TIME '10:30:45.123456' as event_time
   
   -- CREATE TABLE with TIME columns
   CREATE TABLE events (id INT, event_time TIME) USING parquet
   
   -- INSERT with TIME values
   INSERT INTO events VALUES (1, TIME '08:00:00'), (2, TIME '12:30:45.123456')
   
   -- Queries with TIME
   SELECT * FROM events WHERE event_time > TIME '12:00:00' ORDER BY event_time
   ```
   
   **Type Casting:**
   ```sql
   -- STRING ↔ TIME
   SELECT CAST('10:30:45' AS TIME)
   SELECT CAST(TIME '10:30:45' AS STRING)
   
   -- TIMESTAMP ↔ TIME (extracts time portion / combines with epoch date)
   SELECT CAST(TIMESTAMP '2024-01-15 10:30:45' AS TIME)  -- Returns 10:30:45
   SELECT CAST(TIME '10:30:45' AS TIMESTAMP)  -- Returns 1970-01-01 10:30:45
   ```
   
   **File Format Support:**
   - **ORC:** Stored as LONG with TIME semantics, full round-trip correctness
   - **CSV:** Configurable format via `timeFormat` option (default: "HH:mm:ss.SSSSSS")
   - **Parquet:** Native TIME logical type with INT64 storage
   - **JSON:** Time formatting with schema inference
   
   **Hive Integration:**
   - TIME columns stored as BIGINT in Hive tables (Hive lacks native TIME support)
   - Full bidirectional compatibility: Spark writes as BIGINT, Hive reads as BIGINT
   - Transparent conversion via [`TimeType.catalogString`](sql/api/src/main/scala/org/apache/spark/sql/types/TimeType.scala) returning "bigint"
   
   **JDBC/Thrift Server:**
   - TIME columns mapped to `java.sql.Types.TIME` (92)
   - Transmitted as STRING_TYPE over Thrift protocol for maximum compatibility
   - Complete metadata support in JDBC result sets
   
   **Error Handling:**
   - Invalid time strings return NULL (standard mode) or throw exceptions (ANSI mode)
   - Out-of-range values rejected with clear error messages
   
   ## 4. Testing
   
   **Comprehensive Test Coverage (20+ test suites):**
   
   **Core SQL Tests:**
   - TIME literals, parsing, validation
   - CREATE TABLE, INSERT, SELECT operations
   - Type casting covering all conversions (STRING, TIMESTAMP, BIGINT)
   
   **File Format Tests:**
   - [`OrcTimeTypeSuite.scala`](sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/orc/OrcTimeTypeSuite.scala) - ORC read/write, round-trip correctness, NULL handling, edge cases
   - CSV with custom formats, microsecond precision preservation
   - Parquet and JSON format tests
   
   **Hive Integration Tests:**
   - [`HiveTimeTypeSuite.scala`](sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveTimeTypeSuite.scala) - Hive table creation, INSERT/SELECT, BIGINT storage verification
   
   **JDBC/Thrift Server Tests:**
   - Type mapping, query execution, NULL values
   - [`TimeTypeMappingTest.scala`](sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/TimeTypeMappingTest.scala) - JDBC type code verification, column metadata
   
   **Expression Tests:**
   - Cast operations, type coercion, aggregate functions (MIN, MAX, COUNT, DISTINCT)
   - Window functions, DateTime expressions
   
   **Test Status:**
   -  Core tests: PASSING
   -  File format tests: PASSING
   -  Hive tests: PASSING
   -  Some Thrift server tests require full distribution build (infrastructure issue, not TIME type issue)
   
   **Verified Behaviors:**
   - Microsecond precision maintained throughout all operations
   - NULL values handled correctly in all contexts
   - Edge values work (midnight: `00:00:00`, maximum: `23:59:59.999999`)
   - Round-trip correctness in all file formats
   - Schema preservation across write/read cycles
   - ANSI mode compliance for error handling
   
   ## 5. Notable Caveats/Uncertainties
   
   **Hive Compatibility Approach:**
   - **Design Decision:** TIME stored as BIGINT in Hive tables (Hive lacks native TIME support)
   - **Rationale:** Ensures maximum compatibility with existing Hive infrastructure while preserving full precision
   - **Implementation:** [`TimeType.catalogString`](sql/api/src/main/scala/org/apache/spark/sql/types/TimeType.scala) returns "bigint", [`HiveExternalCatalog`](sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala:1477) marks TIME as Hive-compatible
   - **Trade-off:** Hive sees BIGINT values (microseconds), not formatted time strings, but maintains full bidirectional compatibility
   
   **Timezone Handling:**
   - TIME values are timezone-agnostic (represent local time-of-day only)
   - No timezone information stored with TIME values
   - Consistent with SQL:2016 standard TIME semantics
   
   **Test Infrastructure:**
   - Some Thrift server tests require full Spark distribution build (`./build/mvn clean package`)
   - Reason: HiveThriftServer2 spawns separate JVM loading JARs from `assembly/target/`
   - Not a TIME type limitation, but a test infrastructure requirement
   
   **Performance Characteristics:**
   - Storage: 8 bytes per value (same as BIGINT)
   - Fast integer-based comparisons and sorting
   - Code generation for hot paths
   - Predicate pushdown supported in file formats
   - Columnar compression in Parquet/ORC
   
   
   **Summary:** This PR adds production-ready SQL TIME type support to Apache Spark 3.5.4, implementing SQL:2016 standards with microsecond precision. The implementation spans 87+ files, includes 20+ comprehensive test suites, and provides full integration with Spark's SQL engine, file formats (ORC, Parquet, CSV, JSON), Hive (via BIGINT mapping), and JDBC/Thrift server interfaces.


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] Vandana ibm 3.5.4 [spark]

Posted by "VandanaSah (via GitHub)" <gi...@apache.org>.
VandanaSah closed pull request #55411: Vandana ibm 3.5.4
URL: https://github.com/apache/spark/pull/55411


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] Vandana ibm 3.5.4 [spark]

Posted by "VandanaSah (via GitHub)" <gi...@apache.org>.
VandanaSah closed pull request #55411: Vandana ibm 3.5.4
URL: https://github.com/apache/spark/pull/55411


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org