-
Notifications
You must be signed in to change notification settings - Fork 62
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
Cast Impl & Char_length & Abs function #1363
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
348 changes: 342 additions & 6 deletions
348
partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCast.kt
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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 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 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
174 changes: 174 additions & 0 deletions
174
partiql-spi/src/main/kotlin/org/partiql/spi/connector/sql/builtins/FnAbs.kt
This file contains 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,174 @@ | ||
// ktlint-disable filename | ||
@file:Suppress("ClassName") | ||
|
||
package org.partiql.spi.connector.sql.builtins | ||
|
||
import org.partiql.spi.fn.Fn | ||
import org.partiql.spi.fn.FnExperimental | ||
import org.partiql.spi.fn.FnParameter | ||
import org.partiql.spi.fn.FnSignature | ||
import org.partiql.value.DecimalValue | ||
import org.partiql.value.Float32Value | ||
import org.partiql.value.Float64Value | ||
import org.partiql.value.Int16Value | ||
import org.partiql.value.Int32Value | ||
import org.partiql.value.Int64Value | ||
import org.partiql.value.Int8Value | ||
import org.partiql.value.IntValue | ||
import org.partiql.value.PartiQLValue | ||
import org.partiql.value.PartiQLValueExperimental | ||
import org.partiql.value.PartiQLValueType.DECIMAL_ARBITRARY | ||
import org.partiql.value.PartiQLValueType.FLOAT32 | ||
import org.partiql.value.PartiQLValueType.FLOAT64 | ||
import org.partiql.value.PartiQLValueType.INT | ||
import org.partiql.value.PartiQLValueType.INT16 | ||
import org.partiql.value.PartiQLValueType.INT32 | ||
import org.partiql.value.PartiQLValueType.INT64 | ||
import org.partiql.value.PartiQLValueType.INT8 | ||
import org.partiql.value.check | ||
import org.partiql.value.decimalValue | ||
import org.partiql.value.float32Value | ||
import org.partiql.value.float64Value | ||
import org.partiql.value.int16Value | ||
import org.partiql.value.int32Value | ||
import org.partiql.value.int64Value | ||
import org.partiql.value.int8Value | ||
import org.partiql.value.intValue | ||
import kotlin.math.absoluteValue | ||
|
||
// TODO: When negate a negative value, we need to consider overflow | ||
@OptIn(PartiQLValueExperimental::class, FnExperimental::class) | ||
internal object Fn_ABS__INT8__INT8 : Fn { | ||
|
||
override val signature = FnSignature( | ||
name = "abs", | ||
returns = INT8, | ||
parameters = listOf(FnParameter("value", INT8)), | ||
isNullCall = true, | ||
isNullable = false, | ||
) | ||
|
||
override fun invoke(args: Array<PartiQLValue>): Int8Value { | ||
val value = args[0].check<Int8Value>().value!! | ||
return if (value < 0) int8Value(value.times(-1).toByte()) else int8Value(value) | ||
} | ||
} | ||
|
||
@OptIn(PartiQLValueExperimental::class, FnExperimental::class) | ||
internal object Fn_ABS__INT16__INT16 : Fn { | ||
|
||
override val signature = FnSignature( | ||
name = "abs", | ||
returns = INT16, | ||
parameters = listOf(FnParameter("value", INT16)), | ||
isNullCall = true, | ||
isNullable = false, | ||
) | ||
|
||
override fun invoke(args: Array<PartiQLValue>): Int16Value { | ||
val value = args[0].check<Int16Value>().value!! | ||
return if (value < 0) int16Value(value.times(-1).toShort()) else int16Value(value) | ||
} | ||
} | ||
|
||
@OptIn(PartiQLValueExperimental::class, FnExperimental::class) | ||
internal object Fn_ABS__INT32__INT32 : Fn { | ||
|
||
override val signature = FnSignature( | ||
name = "abs", | ||
returns = INT32, | ||
parameters = listOf(FnParameter("value", INT32)), | ||
isNullCall = true, | ||
isNullable = false, | ||
) | ||
|
||
override fun invoke(args: Array<PartiQLValue>): Int32Value { | ||
val value = args[0].check<Int32Value>().value!! | ||
return int32Value(value.absoluteValue) | ||
} | ||
} | ||
|
||
@OptIn(PartiQLValueExperimental::class, FnExperimental::class) | ||
internal object Fn_ABS__INT64__INT64 : Fn { | ||
|
||
override val signature = FnSignature( | ||
name = "abs", | ||
returns = INT64, | ||
parameters = listOf(FnParameter("value", INT64)), | ||
isNullCall = true, | ||
isNullable = false, | ||
) | ||
|
||
override fun invoke(args: Array<PartiQLValue>): Int64Value { | ||
val value = args[0].check<Int64Value>().value!! | ||
return int64Value(value.absoluteValue) | ||
} | ||
} | ||
|
||
@OptIn(PartiQLValueExperimental::class, FnExperimental::class) | ||
internal object Fn_ABS__INT__INT : Fn { | ||
|
||
override val signature = FnSignature( | ||
name = "abs", | ||
returns = INT, | ||
parameters = listOf(FnParameter("value", INT)), | ||
isNullCall = true, | ||
isNullable = false, | ||
) | ||
|
||
override fun invoke(args: Array<PartiQLValue>): IntValue { | ||
val value = args[0].check<IntValue>().value!! | ||
return intValue(value.abs()) | ||
} | ||
} | ||
|
||
@OptIn(PartiQLValueExperimental::class, FnExperimental::class) | ||
internal object Fn_ABS__DECIMAL_ARBITRARY__DECIMAL_ARBITRARY : Fn { | ||
|
||
override val signature = FnSignature( | ||
name = "abs", | ||
returns = DECIMAL_ARBITRARY, | ||
parameters = listOf(FnParameter("value", DECIMAL_ARBITRARY)), | ||
isNullCall = true, | ||
isNullable = false, | ||
) | ||
|
||
override fun invoke(args: Array<PartiQLValue>): DecimalValue { | ||
val value = args[0].check<DecimalValue>().value!! | ||
return decimalValue(value.abs()) | ||
} | ||
} | ||
|
||
@OptIn(PartiQLValueExperimental::class, FnExperimental::class) | ||
internal object Fn_ABS__FLOAT32__FLOAT32 : Fn { | ||
|
||
override val signature = FnSignature( | ||
name = "abs", | ||
returns = FLOAT32, | ||
parameters = listOf(FnParameter("value", FLOAT32)), | ||
isNullCall = true, | ||
isNullable = false, | ||
) | ||
|
||
override fun invoke(args: Array<PartiQLValue>): Float32Value { | ||
val value = args[0].check<Float32Value>().value!! | ||
return float32Value(value.absoluteValue) | ||
} | ||
} | ||
|
||
@OptIn(PartiQLValueExperimental::class, FnExperimental::class) | ||
internal object Fn_ABS__FLOAT64__FLOAT64 : Fn { | ||
|
||
override val signature = FnSignature( | ||
name = "abs", | ||
returns = FLOAT64, | ||
parameters = listOf(FnParameter("value", FLOAT64)), | ||
isNullCall = true, | ||
isNullable = false, | ||
) | ||
|
||
override fun invoke(args: Array<PartiQLValue>): Float64Value { | ||
val value = args[0].check<Float64Value>().value!! | ||
return float64Value(value.absoluteValue) | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
partiql-spi/src/main/kotlin/org/partiql/spi/connector/sql/builtins/FnCharLength.kt
This file contains 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,78 @@ | ||
// ktlint-disable filename | ||
@file:Suppress("ClassName") | ||
|
||
package org.partiql.spi.connector.sql.builtins | ||
|
||
import org.partiql.spi.fn.Fn | ||
import org.partiql.spi.fn.FnExperimental | ||
import org.partiql.spi.fn.FnParameter | ||
import org.partiql.spi.fn.FnSignature | ||
import org.partiql.value.ClobValue | ||
import org.partiql.value.Int32Value | ||
import org.partiql.value.PartiQLValue | ||
import org.partiql.value.PartiQLValueExperimental | ||
import org.partiql.value.PartiQLValueType.CLOB | ||
import org.partiql.value.PartiQLValueType.INT32 | ||
import org.partiql.value.PartiQLValueType.STRING | ||
import org.partiql.value.PartiQLValueType.SYMBOL | ||
import org.partiql.value.StringValue | ||
import org.partiql.value.SymbolValue | ||
import org.partiql.value.check | ||
import org.partiql.value.int32Value | ||
|
||
@OptIn(PartiQLValueExperimental::class, FnExperimental::class) | ||
internal object Fn_CHAR_LENGTH__STRING__INT : Fn { | ||
|
||
override val signature = FnSignature( | ||
name = "char_length", | ||
returns = INT32, | ||
parameters = listOf( | ||
FnParameter("value", STRING), | ||
), | ||
isNullCall = true, | ||
isNullable = false, | ||
) | ||
|
||
override fun invoke(args: Array<PartiQLValue>): Int32Value { | ||
val value = args[0].check<StringValue>().value!! | ||
return int32Value(value.codePointCount(0, value.length)) | ||
} | ||
} | ||
|
||
@OptIn(PartiQLValueExperimental::class, FnExperimental::class) | ||
internal object Fn_CHAR_LENGTH__SYMBOL__INT : Fn { | ||
|
||
override val signature = FnSignature( | ||
name = "char_length", | ||
returns = INT32, | ||
parameters = listOf( | ||
FnParameter("lhs", SYMBOL), | ||
), | ||
isNullCall = true, | ||
isNullable = false, | ||
) | ||
|
||
override fun invoke(args: Array<PartiQLValue>): Int32Value { | ||
val value = args[0].check<SymbolValue>().value!! | ||
return int32Value(value.codePointCount(0, value.length)) | ||
} | ||
} | ||
|
||
@OptIn(PartiQLValueExperimental::class, FnExperimental::class) | ||
internal object Fn_CHAR_LENGTH__CLOB__INT : Fn { | ||
|
||
override val signature = FnSignature( | ||
name = "char_length", | ||
returns = INT32, | ||
parameters = listOf( | ||
FnParameter("lhs", CLOB), | ||
), | ||
isNullCall = true, | ||
isNullable = false, | ||
) | ||
|
||
override fun invoke(args: Array<PartiQLValue>): Int32Value { | ||
val value = args[0].check<ClobValue>().value!! | ||
return int32Value(value.size) | ||
} | ||
} |
Oops, something went wrong.
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.
I'm very curious to explore why we have the reserved function names at all. Other SQL ANTLR grammars simply use a qualified name. I don't think we should change it here, but let's check with John as to why he included those.
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.
Agree. Maybe we can have an alias parameter in FnSignature or something to resolve the multiple naming issue. (i.e.,
char_length
andcharacter_length
)