Skip to content
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

Configure default timezone #449

Merged
merged 26 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
38f01c6
Changed adding default timezone offset to TIME WITH TIME ZONE from pa…
lziq Sep 22, 2021
ea06c69
Remove unnecessary files
lziq Sep 23, 2021
9728308
Modified comments
lziq Sep 23, 2021
49d23b1
Fix issue 410
lziq Sep 27, 2021
b86a559
Fix issue 410
lziq Sep 27, 2021
82147af
Provide an option in EvaluationSession to configure default timezone.
lziq Sep 28, 2021
dab08fc
Added curly braces for line 2419 in SqlParser
lziq Sep 28, 2021
2bd6c56
Added "DataTimeFormatter" qualifier for line 2420 and 2423 in SqlParser
lziq Sep 28, 2021
a407439
Removed git merge conflict in ask.kt
lziq Sep 28, 2021
1fe1b27
Removed git merge conflict in ask.kt
lziq Sep 28, 2021
27e167d
Changed code style
lziq Sep 28, 2021
5297a5e
Changed code style
lziq Sep 28, 2021
d5bfa8b
Changed code style
lziq Sep 28, 2021
6580491
Changed code style
lziq Sep 28, 2021
0e5d497
Changed code style
lziq Sep 28, 2021
fb754b3
Changed code style
lziq Sep 28, 2021
572acc8
Added more test cases for time evaluation
lziq Sep 28, 2021
27101f4
Changed new field type from Environment to EvaluationSession for `Exp…
lziq Sep 28, 2021
3353c93
Update lang/test/org/partiql/lang/eval/EvaluatingCompilerCastTest.kt
lziq Sep 28, 2021
5882c2e
Update lang/test/org/partiql/lang/eval/EvaluatingCompilerDateTimeTest…
lziq Sep 28, 2021
9748e44
Removed unused package import
lziq Sep 29, 2021
ff122ee
Provided kdoc for `defaultTimezoneOffset` in `EvaluationSession` and …
lziq Sep 29, 2021
919f725
Made changes to `settingDefaultTimezoneOffset` in `EvaluationSessionT…
lziq Sep 29, 2021
ba59139
Merge branch 'configure-default-timezone' of https://github.com/parti…
lziq Sep 29, 2021
f92ee58
Created helper function for default timezone offset cast test cases.
lziq Sep 29, 2021
b7ee8bf
Created helper function for default timezone offset time evaluation t…
lziq Sep 29, 2021
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
6 changes: 3 additions & 3 deletions lang/src/org/partiql/lang/eval/EvaluatingCompiler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import org.partiql.lang.eval.time.Time
import org.partiql.lang.eval.visitors.PartiqlAstSanityValidator
import org.partiql.lang.syntax.SqlParser
import org.partiql.lang.util.*
import org.partiql.lang.util.DEFAULT_TIMEZONE_OFFSET
import java.math.*
import java.time.ZoneOffset
lziq marked this conversation as resolved.
Show resolved Hide resolved
import java.util.*
import kotlin.collections.*

Expand Down Expand Up @@ -811,7 +811,7 @@ internal class EvaluatingCompiler(
val locationMeta = metas.sourceLocationMeta
thunkFactory.thunkEnv(metas) { env ->
val valueToCast = expThunk(env)
valueToCast.cast(dataType, valueFactory, locationMeta)
valueToCast.cast(dataType, valueFactory, locationMeta, env)
}
}
}
Expand Down Expand Up @@ -2010,7 +2010,7 @@ internal class EvaluatingCompiler(
second,
nano,
precision,
if (with_time_zone && tz_minutes == null) DEFAULT_TIMEZONE_OFFSET.totalMinutes else tz_minutes
if (with_time_zone && tz_minutes == null) it.session.defaultTimezoneOffset.totalMinutes else tz_minutes
)
)
}
Expand Down
13 changes: 11 additions & 2 deletions lang/src/org/partiql/lang/eval/EvaluationSession.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.partiql.lang.eval

import com.amazon.ion.*
import java.time.ZoneOffset

/**
* Evaluation Session. Holds user defined constants used during evaluation. Each value has a default value that can
Expand All @@ -26,7 +27,8 @@ import com.amazon.ion.*
*/
class EvaluationSession private constructor(val globals: Bindings<ExprValue>,
val parameters: List<ExprValue>,
val now: Timestamp) {
val now: Timestamp,
val defaultTimezoneOffset: ZoneOffset) {
lziq marked this conversation as resolved.
Show resolved Hide resolved
companion object {
/**
* Java style builder to construct a new [EvaluationSession]. Uses the default value for any non specified field
Expand Down Expand Up @@ -68,8 +70,15 @@ class EvaluationSession private constructor(val globals: Bindings<ExprValue>,
return this
}

private var defaultTimezoneOffset: ZoneOffset = ZoneOffset.UTC
fun defaultTimezoneOffset(value: ZoneOffset): Builder {
defaultTimezoneOffset = value
return this
}

fun build(): EvaluationSession = EvaluationSession(now = now ?: Timestamp.nowZ(),
parameters = parameters,
globals = globals)
globals = globals,
defaultTimezoneOffset = defaultTimezoneOffset)
}
}
7 changes: 4 additions & 3 deletions lang/src/org/partiql/lang/eval/ExprValueExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ private val genericTimeRegex = Regex("\\d\\d:\\d\\d:\\d\\d(\\.\\d*)?([+|-]\\d\\d
fun ExprValue.cast(
targetDataType: DataType,
valueFactory: ExprValueFactory,
locationMeta: SourceLocationMeta?
locationMeta: SourceLocationMeta?,
env: Environment
lziq marked this conversation as resolved.
Show resolved Hide resolved
): ExprValue {

val targetSqlDataType = targetDataType.sqlDataType
Expand Down Expand Up @@ -362,7 +363,7 @@ fun ExprValue.cast(
type == TIME -> {
val time = timeValue()
val timeZoneOffset = when (targetSqlDataType) {
SqlDataType.TIME_WITH_TIME_ZONE -> time.zoneOffset?: DEFAULT_TIMEZONE_OFFSET
SqlDataType.TIME_WITH_TIME_ZONE -> time.zoneOffset?: env.session.defaultTimezoneOffset
else -> null
}
return valueFactory.newTime(
Expand Down Expand Up @@ -405,7 +406,7 @@ fun ExprValue.cast(

// Note that the [genericTimeRegex] has a group to extract the zone offset.
val zoneOffsetString = matcher.group(2)
val zoneOffset = zoneOffsetString?.let { ZoneOffset.of(it) } ?: DEFAULT_TIMEZONE_OFFSET
val zoneOffset = zoneOffsetString?.let { ZoneOffset.of(it) } ?: env.session.defaultTimezoneOffset

return valueFactory.newTime(
Time.of(
Expand Down
8 changes: 0 additions & 8 deletions lang/src/org/partiql/lang/eval/time/TimeExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ internal val genericTimeRegex = Regex("\\d\\d:\\d\\d:\\d\\d(\\.\\d*)?([+|-]\\d\\
*/
internal val DATE_PATTERN_REGEX = Regex("\\d\\d\\d\\d-\\d\\d-\\d\\d")

/**
* If the default timezone offset is not provided with [CompileOptions], it defaults to [ZoneOffset.UTC].
* (The option to specify default timezone offset will be available once [#410](https://github.com/partiql/partiql-lang-kotlin/issues/410) is resolved)
*
* If timezone offset is not specified explicitly (when using `TIME WITH TIME ZONE`), the default time zone offset is used.
*/
internal val DEFAULT_TIMEZONE_OFFSET = ZoneOffset.UTC

/**
* Returns the string representation of the [ZoneOffset] in HH:mm format.
*/
Expand Down
Loading