Skip to content

Fix Timestamp Type Parsing Issue. #1284

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

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Thank you to all who have contributed!

### Fixed
- Fixes the CLI hanging on invalid queries. See issue #1230.
- Fixes Timestamp Type parsing issue. Previously Timestamp Type would get parsed to a Time type.

### Removed
- **Breaking** Removed IR factory in favor of static top-level functions. Change `Ast.foo()`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,7 @@ private class AstTranslator(val metas: Map<String, MetaContainer>) : AstBaseVisi
translate(node) { metas -> timestampType(node.precision?.toLong(), metas) }

override fun visitTypeTimestampWithTz(node: Type.TimestampWithTz, ctx: Ctx) =
throw IllegalArgumentException("TIMESTAMP [WITH TIMEZONE] type not supported")
translate(node) { metas -> timestampWithTimeZoneType(node.precision?.toLong(), metas) }

override fun visitTypeInterval(node: Type.Interval, ctx: Ctx) =
throw IllegalArgumentException("INTERVAL type not supported")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,54 @@ class PartiQLParserTest : PartiQLParserTestBase() {
"(is_type (call f) (character_varying_type 200))"
)

@Test
fun callIsTimestamp() = assertExpression(
"t1 IS TIMESTAMP",
"(is_type (id t1 (case_insensitive) (unqualified)) (timestamp_type null))"
)

@Test
fun callIsTime() = assertExpression(
"t1 IS TIME",
"(is_type (id t1 (case_insensitive) (unqualified)) (time_type null))"
)
Comment on lines +368 to +378
Copy link
Member

Choose a reason for hiding this comment

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

Just to avoid potential failures in the future, can you also add the WITH TIME ZONE test to each?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added Tests for Time Zone And Precision.

Copy link
Member

Choose a reason for hiding this comment

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

Did you forget to push? I don't see any changes rn.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry the push command failed due to a rebased...


@Test
fun callIsTimestampWithTimeZone() = assertExpression(
"t1 IS TIMESTAMP WITH TIME ZONE",
"(is_type (id t1 (case_insensitive) (unqualified)) (timestamp_with_time_zone_type null))"
)

@Test
fun callIsTimeWithTimeZone() = assertExpression(
"t1 IS TIME WITH TIME ZONE",
"(is_type (id t1 (case_insensitive) (unqualified)) (time_with_time_zone_type null))"
)

@Test
fun callIsTimestampWithPrecision() = assertExpression(
"t1 IS TIMESTAMP(3)",
"(is_type (id t1 (case_insensitive) (unqualified)) (timestamp_type 3))"
)

@Test
fun callIsTimeWithPrecision() = assertExpression(
"t1 IS TIME(3)",
"(is_type (id t1 (case_insensitive) (unqualified)) (time_type 3))"
)

@Test
fun callIsTimestampWithTimeZoneAndPrecision() = assertExpression(
"t1 IS TIMESTAMP(3) WITH TIME ZONE",
"(is_type (id t1 (case_insensitive) (unqualified)) (timestamp_with_time_zone_type 3))"
)

@Test
fun callIsTimeWithTimeZoneAndPrecision() = assertExpression(
"t1 IS TIME(3) WITH TIME ZONE",
"(is_type (id t1 (case_insensitive) (unqualified)) (time_with_time_zone_type 3))"
)

@Test
fun nullIsNotNull() = assertExpression(
"null IS NOT NULL",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ import org.partiql.ast.typeSymbol
import org.partiql.ast.typeTime
import org.partiql.ast.typeTimeWithTz
import org.partiql.ast.typeTimestamp
import org.partiql.ast.typeTimestampWithTz
import org.partiql.ast.typeTuple
import org.partiql.ast.typeVarchar
import org.partiql.parser.PartiQLLexerException
Expand Down Expand Up @@ -2079,9 +2080,17 @@ internal class PartiQLParserDefault : PartiQLParser {
if (p < 0 || 9 < p) throw error(ctx.precision, "Unsupported time precision")
p
}
when (ctx.ZONE()) {
null -> typeTime(precision)
else -> typeTimeWithTz(precision)

when (ctx.datatype.type) {
GeneratedParser.TIME -> when (ctx.ZONE()) {
null -> typeTime(precision)
else -> typeTimeWithTz(precision)
}
GeneratedParser.TIMESTAMP -> when (ctx.ZONE()) {
null -> typeTimestamp(precision)
else -> typeTimestampWithTz(precision)
}
else -> throw error(ctx.datatype, "Invalid datatype")
}
}

Expand Down