Skip to content

Commit

Permalink
Timestamp Data Model (#1121)
Browse files Browse the repository at this point in the history
* Date time data model
  • Loading branch information
yliuuuu authored Jul 11, 2023
1 parent 8a3c3de commit 44e8a8d
Show file tree
Hide file tree
Showing 34 changed files with 4,838 additions and 903 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Thank you to all who have contributed!
### Added
- Adds `org.partiql.value` (experimental) package for reading/writing PartiQL
values
- Adds PartiQL's Timestamp Data Model.
- Adds support for Timestamp constructor call in Parser.

### Changed

Expand All @@ -45,6 +47,7 @@ Thank you to all who have contributed!
### Contributors
Thank you to all who have contributed!
- @howero
- @yliuuuu
- @<your-username>

## [0.12.0] - 2023-06-14
Expand Down
19 changes: 16 additions & 3 deletions partiql-ast/src/main/pig/partiql.ion
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ may then be further optimized by selecting better implementations of each operat
// Constructors for DateTime types
(date year::int month::int day::int)
(lit_time value::time_value)
(timestamp value::timestamp_value)

// Bag operators
(bag_op op::bag_op_type quantifier::set_quantifier operands::(* expr 2))
Expand Down Expand Up @@ -178,6 +179,19 @@ may then be further optimized by selecting better implementations of each operat
// Time
(product time_value hour::int minute::int second::int nano::int precision::int with_time_zone::bool tz_minutes::(? int))

// Timestamp
(product timestamp_value year::int month::int day::int hour::int minute::int second::ion timezone::(? timezone) precision::(? int) )

(sum timezone
// Unknown time zone -00:00
(unknown_timezone)
// UTC offset ex: -01:30 -> tz_hour = -1, tz_minutes = -30, total offset minutes = -90
// tz_hour is in [-23, 23], timezone minutes is in [-59,59]
// we only need total offset minutes to model this property
(utc_offset offset_minutes::int)
// TODO: Timezone ID not support yet. Ex: US/Pacific
)

// A "step" within a path expression; that is the components of the expression following the root.
(sum path_step
// `someRoot[<expr>]`, or `someRoot.someField` which is equivalent to `someRoot['someField']`.
Expand Down Expand Up @@ -535,9 +549,6 @@ may then be further optimized by selecting better implementations of each operat
// `NUMERIC[(<int> [, int])]`. Elements are precision then scale.
(numeric_type precision::(? int) scale::(? int))

// `TIMESTAMP`
(timestamp_type)

// `CHAR(<int>)`
(character_type length::(? int))

Expand All @@ -557,6 +568,8 @@ may then be further optimized by selecting better implementations of each operat
// Note: This logic is implemented in SqlParser.
(time_type precision::(? int))
(time_with_time_zone_type precision::(? int))
(timestamp_type precision::(? int))
(timestamp_with_time_zone_type precision::(? int))

(struct_type)
(tuple_type)
Expand Down
13 changes: 13 additions & 0 deletions partiql-lang/src/main/kotlin/org/partiql/lang/errors/ErrorCode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ enum class ErrorCode(
"invalid precision used for TIME type"
),

// TODO: We should combine this with the above
PARSE_INVALID_PRECISION_FOR_TIMESTAMP(
ErrorCategory.PARSER,
LOC_TOKEN,
"invalid precision used for TIMESTAMP type"
),

PARSE_INVALID_DATE_STRING(
ErrorCategory.PARSER,
LOC_TOKEN,
Expand All @@ -155,6 +162,12 @@ enum class ErrorCode(
"expected time string to be of the format HH:MM:SS[.dddd...][+|-HH:MM]"
),

PARSE_INVALID_DATETIME_STRING(
ErrorCategory.PARSER,
LOC_TOKEN,
"Invalid timestamp string"
),

PARSE_INVALID_TRIM_SPEC(
ErrorCategory.PARSER,
LOC_TOKEN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ internal class EvaluatingCompiler(

is PartiqlAst.Expr.GraphMatch -> compileGraphMatch(expr, metas)
is PartiqlAst.Expr.CallWindow -> TODO("Evaluating Compiler doesn't support window function")
is PartiqlAst.Expr.Timestamp -> TODO()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ internal class PhysicalPlanCompilerImpl(
is PartiqlPhysical.Expr.BindingsToValues -> compileBindingsToValues(expr)
is PartiqlPhysical.Expr.Pivot -> compilePivot(expr, metas)
is PartiqlPhysical.Expr.GraphMatch -> TODO("Physical compilation of GraphMatch expression")
is PartiqlPhysical.Expr.Timestamp -> TODO()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class SubqueryCoercionVisitorTransform : VisitorTransformBase() {
is PartiqlAst.Expr.CanLosslessCast -> n
is PartiqlAst.Expr.NullIf -> n
is PartiqlAst.Expr.Coalesce -> n
is PartiqlAst.Expr.Timestamp -> TODO()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ class ASTPrettyPrinter {
)
is PartiqlAst.Expr.GraphMatch -> TODO("Unsupported GraphMatch AST node")
is PartiqlAst.Expr.CallWindow -> TODO("PrettyPrinter doesn't support Window Function yet.")
is PartiqlAst.Expr.Timestamp -> TODO()
}

private fun toRecursionTreeList(nodes: List<PartiqlAst.Expr>, attrOfParent: String? = null): List<RecursionTree> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ class QueryPrettyPrinter {
is PartiqlAst.Expr.CallWindow -> TODO()
is PartiqlAst.Expr.GraphMatch -> TODO()
is PartiqlAst.Expr.SessionAttribute -> writeSessionAttribute(node, sb)
is PartiqlAst.Expr.Timestamp -> TODO()
}
}

Expand Down
Loading

1 comment on commit 44e8a8d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JMH Benchmark

Benchmark suite Current: 44e8a8d Previous: 8a3c3de Ratio
org.partiql.jmh.benchmarks.MultipleLikeBenchmark.testPartiQLCompiler15 122.82983370102895 us/op 130.01975235858544 us/op 0.94
org.partiql.jmh.benchmarks.MultipleLikeBenchmark.testPartiQLCompiler30 237.75115327771442 us/op 246.75610469418575 us/op 0.96
org.partiql.jmh.benchmarks.MultipleLikeBenchmark.testPartiQLEvaluator15 522876.47167500004 us/op 458331.87419999996 us/op 1.14
org.partiql.jmh.benchmarks.MultipleLikeBenchmark.testPartiQLEvaluator30 1030297.3623499998 us/op 933554.9735 us/op 1.10
org.partiql.jmh.benchmarks.MultipleLikeBenchmark.testPartiQLEvaluator30WithData10 10490179.39895 us/op 9295372.35175 us/op 1.13
org.partiql.jmh.benchmarks.MultipleLikeBenchmark.testPartiQLParser15 212.72056788119545 us/op 228.00337081526618 us/op 0.93
org.partiql.jmh.benchmarks.MultipleLikeBenchmark.testPartiQLParser30 385.4639718169268 us/op 411.2130564824147 us/op 0.94
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameCaseWhenThen 45.311377346349076 us/op 42.40400816224215 us/op 1.07
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameComplexQuery 62.88984332498535 us/op 57.140869966948834 us/op 1.10
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameComplexQuery01 328.39527910843424 us/op 274.5747036686354 us/op 1.20
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameComplexQuery02 545.2115894833571 us/op 478.76029318432546 us/op 1.14
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameExceptUnionIntersectSixty 214.07596988899323 us/op 221.0970706492655 us/op 0.97
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameExec20Expressions 71.0962901641523 us/op 66.59623506979584 us/op 1.07
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameFromLet 49.32462466567836 us/op 45.35474809139243 us/op 1.09
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameGraphPattern 45.985833061025964 us/op 45.67217838660733 us/op 1.01
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameGraphPreFilters 67.53349526202793 us/op 67.57473200888998 us/op 1.00
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameGroupLimit 56.31541191202477 us/op 53.83308064495393 us/op 1.05
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameLongFromSourceOrderBy 68.2015632262747 us/op 63.326895350304845 us/op 1.08
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameManyJoins 67.43972696924679 us/op 63.21463067884322 us/op 1.07
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameNestedAggregates 123.31266290152296 us/op 110.77609098708453 us/op 1.11
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameNestedParen 21.698295396796638 us/op 19.026516229549635 us/op 1.14
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNamePivot 71.77230005032435 us/op 69.018841197869 us/op 1.04
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameQuery15OrsAndLikes 230.0034077931379 us/op 221.60634994301458 us/op 1.04
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameQuery30Plus 122.89349154934953 us/op 114.93926101445986 us/op 1.07
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameQueryFunc 56.306651766325956 us/op 50.552239890660275 us/op 1.11
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameQueryFuncInProjection 126.40443153702486 us/op 109.22385764208441 us/op 1.16
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameQueryList 84.07399305751096 us/op 79.17519348011305 us/op 1.06
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameQueryNestedSelect 811.6922139911352 us/op 718.8262891383087 us/op 1.13
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameQuerySimple 19.651027235874395 us/op 16.996649697014032 us/op 1.16
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameSeveralJoins 26.276331837176514 us/op 23.9222320159664 us/op 1.10
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameSeveralProjections 83.5124567090754 us/op 78.2128440478692 us/op 1.07
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameSeveralSelect 222.56927173191121 us/op 208.58321850140032 us/op 1.07
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameSimpleInsert 33.85542560754189 us/op 30.666358958459973 us/op 1.10
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameSomeJoins 26.2490049299208 us/op 23.289578680731285 us/op 1.13
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameSomeProjections 35.37151147181547 us/op 32.13847388226794 us/op 1.10
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameSomeSelect 55.33641133877815 us/op 54.149858510232335 us/op 1.02
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameTimeZone 29.13900524764465 us/op 25.553154869420545 us/op 1.14
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameVeryLongQuery 362.7831861851163 us/op 329.2953284425372 us/op 1.10
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameVeryLongQuery01 1070.7843317478732 us/op 1021.8930164459618 us/op 1.05
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameCaseWhenThen 30.90282898240635 us/op 31.16636692983182 us/op 0.99
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameComplexQuery 265.72716663227004 us/op 269.02346860660396 us/op 0.99
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameComplexQuery01 123.51171318440007 us/op 124.59603354730055 us/op 0.99
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameExceptUnionIntersectSixty 243.42138285471475 us/op 260.6902744990351 us/op 0.93
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameExec20Expressions 73.46040600421557 us/op 77.0211589058376 us/op 0.95
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameFromLet 44.3074968551868 us/op 44.90142184864675 us/op 0.99
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameGraphPattern 44.06504763008975 us/op 45.95396692062057 us/op 0.96
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameGraphPreFilters 75.42080560598758 us/op 79.36865018617108 us/op 0.95
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameGroupLimit 38.38885507580589 us/op 37.94795227188485 us/op 1.01
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameLongFromSourceOrderBy 147.26280984456258 us/op 157.4323447161409 us/op 0.94
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameManyJoins 49.78906902367227 us/op 50.847917400370214 us/op 0.98
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameNestedAggregates 107.67514384278145 us/op 110.30771190345794 us/op 0.98
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameNestedParen 87.72891932024953 us/op 94.09357173850233 us/op 0.93
org.partiql.jmh.benchmarks.ParserBenchmark.parseNamePivot 77.67617957871913 us/op 79.0689846061499 us/op 0.98
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameQuery15OrsAndLikes 207.04811314941463 us/op 204.13540641617917 us/op 1.01
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameQuery30Plus 67.07175782270352 us/op 67.18639882714943 us/op 1.00
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameQueryFunc 145.85035179544275 us/op 140.72922974680512 us/op 1.04
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameQueryFuncInProjection 111.77683997775284 us/op 105.18048113023221 us/op 1.06
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameQueryList 90.20098806638515 us/op 94.42043688103755 us/op 0.96
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameQueryNestedSelect 149.61759659982772 us/op 155.51899775022713 us/op 0.96
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameQuerySimple 15.796056276859733 us/op 14.889190375583226 us/op 1.06
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameSeveralJoins 83.94672510745917 us/op 86.12210208569877 us/op 0.97
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameSeveralProjections 66.15077698573907 us/op 69.51213480673346 us/op 0.95
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameSeveralSelect 131.28463849867495 us/op 132.93250540328728 us/op 0.99
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameSimpleInsert 25.846898695125265 us/op 24.918834945711303 us/op 1.04
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameSomeJoins 24.520345618461374 us/op 24.623757287270855 us/op 1.00
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameSomeProjections 22.449452927847638 us/op 21.606022910380297 us/op 1.04
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameSomeSelect 41.54487022139408 us/op 42.1822029280838 us/op 0.98
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameTimeZone 11.232094815766697 us/op 9.868488880288691 us/op 1.14
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameVeryLongQuery 463.73348476721884 us/op 481.9808349072382 us/op 0.96
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameVeryLongQuery01 1356.747829337987 us/op 1316.6653650495878 us/op 1.03
org.partiql.jmh.benchmarks.PartiQLBenchmark.testPartiQLCompiler 10.156162944006562 us/op 11.497316282604453 us/op 0.88
org.partiql.jmh.benchmarks.PartiQLBenchmark.testPartiQLEvaluator 2.5044550320114425 us/op 2.4654832516412566 us/op 1.02
org.partiql.jmh.benchmarks.PartiQLBenchmark.testPartiQLParser 13.968448217078924 us/op 13.70679981006493 us/op 1.02

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.