Skip to content

Commit 3955836

Browse files
authored
Merge 7cf19fa into c7466e4
2 parents c7466e4 + 7cf19fa commit 3955836

File tree

13 files changed

+404
-136
lines changed

13 files changed

+404
-136
lines changed

plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnAnd.kt

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ import org.partiql.spi.function.PartiQLFunction
77
import org.partiql.spi.function.PartiQLFunctionExperimental
88
import org.partiql.types.function.FunctionParameter
99
import org.partiql.types.function.FunctionSignature
10+
import org.partiql.value.BoolValue
1011
import org.partiql.value.PartiQLValue
1112
import org.partiql.value.PartiQLValueExperimental
1213
import org.partiql.value.PartiQLValueType.BOOL
1314
import org.partiql.value.PartiQLValueType.MISSING
15+
import org.partiql.value.boolValue
16+
import org.partiql.value.check
1417

1518
@OptIn(PartiQLValueExperimental::class, PartiQLFunctionExperimental::class)
1619
internal object Fn_AND__BOOL_BOOL__BOOL : PartiQLFunction.Scalar {
@@ -27,7 +30,14 @@ internal object Fn_AND__BOOL_BOOL__BOOL : PartiQLFunction.Scalar {
2730
)
2831

2932
override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
30-
TODO("Function and not implemented")
33+
val lhs = args[0].check<BoolValue>().value
34+
val rhs = args[1].check<BoolValue>().value
35+
val toReturn = when {
36+
lhs == false || rhs == false -> false
37+
lhs == null || rhs == null -> null
38+
else -> true
39+
}
40+
return boolValue(toReturn)
3141
}
3242
}
3343

@@ -46,7 +56,11 @@ internal object Fn_AND__MISSING_BOOL__BOOL : PartiQLFunction.Scalar {
4656
)
4757

4858
override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
49-
TODO("Function and not implemented")
59+
val rhs = args[1].check<BoolValue>().value
60+
return when (rhs) {
61+
false -> boolValue(false)
62+
else -> boolValue(null)
63+
}
5064
}
5165
}
5266

@@ -65,7 +79,11 @@ internal object Fn_AND__BOOL_MISSING__BOOL : PartiQLFunction.Scalar {
6579
)
6680

6781
override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
68-
TODO("Function and not implemented")
82+
val lhs = args[0].check<BoolValue>().value
83+
return when (lhs) {
84+
false -> boolValue(false)
85+
else -> boolValue(null)
86+
}
6987
}
7088
}
7189

@@ -84,6 +102,6 @@ internal object Fn_AND__MISSING_MISSING__BOOL : PartiQLFunction.Scalar {
84102
)
85103

86104
override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
87-
TODO("Function and not implemented")
105+
return boolValue(null)
88106
}
89107
}

plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnBitwiseAnd.kt

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,25 @@ import org.partiql.spi.function.PartiQLFunction
77
import org.partiql.spi.function.PartiQLFunctionExperimental
88
import org.partiql.types.function.FunctionParameter
99
import org.partiql.types.function.FunctionSignature
10+
import org.partiql.value.Int16Value
11+
import org.partiql.value.Int32Value
12+
import org.partiql.value.Int64Value
13+
import org.partiql.value.Int8Value
14+
import org.partiql.value.IntValue
1015
import org.partiql.value.PartiQLValue
1116
import org.partiql.value.PartiQLValueExperimental
1217
import org.partiql.value.PartiQLValueType.INT
1318
import org.partiql.value.PartiQLValueType.INT16
1419
import org.partiql.value.PartiQLValueType.INT32
1520
import org.partiql.value.PartiQLValueType.INT64
1621
import org.partiql.value.PartiQLValueType.INT8
22+
import org.partiql.value.check
23+
import org.partiql.value.int16Value
24+
import org.partiql.value.int32Value
25+
import org.partiql.value.int64Value
26+
import org.partiql.value.int8Value
27+
import org.partiql.value.intValue
28+
import kotlin.experimental.and
1729

1830
@OptIn(PartiQLValueExperimental::class, PartiQLFunctionExperimental::class)
1931
internal object Fn_BITWISE_AND__INT8_INT8__INT8 : PartiQLFunction.Scalar {
@@ -29,8 +41,10 @@ internal object Fn_BITWISE_AND__INT8_INT8__INT8 : PartiQLFunction.Scalar {
2941
isNullable = false,
3042
)
3143

32-
override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
33-
TODO("Function bitwise_and not implemented")
44+
override fun invoke(args: Array<PartiQLValue>): Int8Value {
45+
val arg0 = args[0].check<Int8Value>().value!!
46+
val arg1 = args[1].check<Int8Value>().value!!
47+
return int8Value(arg0 and arg1)
3448
}
3549
}
3650

@@ -48,8 +62,10 @@ internal object Fn_BITWISE_AND__INT16_INT16__INT16 : PartiQLFunction.Scalar {
4862
isNullable = false,
4963
)
5064

51-
override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
52-
TODO("Function bitwise_and not implemented")
65+
override fun invoke(args: Array<PartiQLValue>): Int16Value {
66+
val arg0 = args[0].check<Int16Value>().value!!
67+
val arg1 = args[1].check<Int16Value>().value!!
68+
return int16Value(arg0 and arg1)
5369
}
5470
}
5571

@@ -67,8 +83,10 @@ internal object Fn_BITWISE_AND__INT32_INT32__INT32 : PartiQLFunction.Scalar {
6783
isNullable = false,
6884
)
6985

70-
override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
71-
TODO("Function bitwise_and not implemented")
86+
override fun invoke(args: Array<PartiQLValue>): Int32Value {
87+
val arg0 = args[0].check<Int32Value>().value!!
88+
val arg1 = args[1].check<Int32Value>().value!!
89+
return int32Value(arg0 and arg1)
7290
}
7391
}
7492

@@ -86,8 +104,10 @@ internal object Fn_BITWISE_AND__INT64_INT64__INT64 : PartiQLFunction.Scalar {
86104
isNullable = false,
87105
)
88106

89-
override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
90-
TODO("Function bitwise_and not implemented")
107+
override fun invoke(args: Array<PartiQLValue>): Int64Value {
108+
val arg0 = args[0].check<Int64Value>().value!!
109+
val arg1 = args[1].check<Int64Value>().value!!
110+
return int64Value(arg0 and arg1)
91111
}
92112
}
93113

@@ -105,7 +125,9 @@ internal object Fn_BITWISE_AND__INT_INT__INT : PartiQLFunction.Scalar {
105125
isNullable = false,
106126
)
107127

108-
override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
109-
TODO("Function bitwise_and not implemented")
128+
override fun invoke(args: Array<PartiQLValue>): IntValue {
129+
val arg0 = args[0].check<IntValue>().value!!
130+
val arg1 = args[1].check<IntValue>().value!!
131+
return intValue(arg0 and arg1)
110132
}
111133
}

plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnConcat.kt

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@ import org.partiql.spi.function.PartiQLFunction
77
import org.partiql.spi.function.PartiQLFunctionExperimental
88
import org.partiql.types.function.FunctionParameter
99
import org.partiql.types.function.FunctionSignature
10+
import org.partiql.value.ClobValue
1011
import org.partiql.value.PartiQLValue
1112
import org.partiql.value.PartiQLValueExperimental
1213
import org.partiql.value.PartiQLValueType.CLOB
1314
import org.partiql.value.PartiQLValueType.STRING
1415
import org.partiql.value.PartiQLValueType.SYMBOL
16+
import org.partiql.value.StringValue
17+
import org.partiql.value.SymbolValue
18+
import org.partiql.value.check
19+
import org.partiql.value.clobValue
20+
import org.partiql.value.stringValue
21+
import org.partiql.value.symbolValue
1522

1623
@OptIn(PartiQLValueExperimental::class, PartiQLFunctionExperimental::class)
1724
internal object Fn_CONCAT__STRING_STRING__STRING : PartiQLFunction.Scalar {
@@ -27,8 +34,11 @@ internal object Fn_CONCAT__STRING_STRING__STRING : PartiQLFunction.Scalar {
2734
isNullable = false,
2835
)
2936

30-
override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
31-
TODO("Function concat not implemented")
37+
override fun invoke(args: Array<PartiQLValue>): StringValue {
38+
39+
val arg0 = args[0].check<StringValue>().value!!
40+
val arg1 = args[1].check<StringValue>().value!!
41+
return stringValue(arg0 + arg1)
3242
}
3343
}
3444

@@ -46,8 +56,12 @@ internal object Fn_CONCAT__SYMBOL_SYMBOL__SYMBOL : PartiQLFunction.Scalar {
4656
isNullable = false,
4757
)
4858

49-
override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
50-
TODO("Function concat not implemented")
59+
// TODO: We are still debating on whether symbol is a value. It looks like it may not be, and therefore, this
60+
// will be removed.
61+
override fun invoke(args: Array<PartiQLValue>): SymbolValue {
62+
val arg0 = args[0].check<SymbolValue>().value!!
63+
val arg1 = args[1].check<SymbolValue>().value!!
64+
return symbolValue(arg0 + arg1)
5165
}
5266
}
5367

@@ -65,7 +79,9 @@ internal object Fn_CONCAT__CLOB_CLOB__CLOB : PartiQLFunction.Scalar {
6579
isNullable = false,
6680
)
6781

68-
override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
69-
TODO("Function concat not implemented")
82+
override fun invoke(args: Array<PartiQLValue>): ClobValue {
83+
val arg0 = args[0].check<ClobValue>().value!!
84+
val arg1 = args[1].check<ClobValue>().value!!
85+
return clobValue(arg0 + arg1)
7086
}
7187
}

plugins/partiql-plugin/src/main/kotlin/org/partiql/plugin/internal/fn/scalar/FnDivide.kt

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ import org.partiql.spi.function.PartiQLFunction
77
import org.partiql.spi.function.PartiQLFunctionExperimental
88
import org.partiql.types.function.FunctionParameter
99
import org.partiql.types.function.FunctionSignature
10+
import org.partiql.value.DecimalValue
11+
import org.partiql.value.Float32Value
12+
import org.partiql.value.Float64Value
13+
import org.partiql.value.Int16Value
14+
import org.partiql.value.Int32Value
15+
import org.partiql.value.Int64Value
16+
import org.partiql.value.Int8Value
17+
import org.partiql.value.IntValue
1018
import org.partiql.value.PartiQLValue
1119
import org.partiql.value.PartiQLValueExperimental
1220
import org.partiql.value.PartiQLValueType.DECIMAL_ARBITRARY
@@ -17,6 +25,15 @@ import org.partiql.value.PartiQLValueType.INT16
1725
import org.partiql.value.PartiQLValueType.INT32
1826
import org.partiql.value.PartiQLValueType.INT64
1927
import org.partiql.value.PartiQLValueType.INT8
28+
import org.partiql.value.check
29+
import org.partiql.value.decimalValue
30+
import org.partiql.value.float32Value
31+
import org.partiql.value.float64Value
32+
import org.partiql.value.int16Value
33+
import org.partiql.value.int32Value
34+
import org.partiql.value.int64Value
35+
import org.partiql.value.int8Value
36+
import org.partiql.value.intValue
2037

2138
@OptIn(PartiQLValueExperimental::class, PartiQLFunctionExperimental::class)
2239
internal object Fn_DIVIDE__INT8_INT8__INT8 : PartiQLFunction.Scalar {
@@ -32,8 +49,10 @@ internal object Fn_DIVIDE__INT8_INT8__INT8 : PartiQLFunction.Scalar {
3249
isNullable = false,
3350
)
3451

35-
override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
36-
TODO("Function divide not implemented")
52+
override fun invoke(args: Array<PartiQLValue>): Int8Value {
53+
val arg0 = args[0].check<Int8Value>().value!!
54+
val arg1 = args[1].check<Int8Value>().value!!
55+
return int8Value((arg0 / arg1).toByte())
3756
}
3857
}
3958

@@ -51,8 +70,10 @@ internal object Fn_DIVIDE__INT16_INT16__INT16 : PartiQLFunction.Scalar {
5170
isNullable = false,
5271
)
5372

54-
override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
55-
TODO("Function divide not implemented")
73+
override fun invoke(args: Array<PartiQLValue>): Int16Value {
74+
val arg0 = args[0].check<Int16Value>().value!!
75+
val arg1 = args[1].check<Int16Value>().value!!
76+
return int16Value((arg0 / arg1).toShort())
5677
}
5778
}
5879

@@ -70,8 +91,10 @@ internal object Fn_DIVIDE__INT32_INT32__INT32 : PartiQLFunction.Scalar {
7091
isNullable = false,
7192
)
7293

73-
override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
74-
TODO("Function divide not implemented")
94+
override fun invoke(args: Array<PartiQLValue>): Int32Value {
95+
val arg0 = args[0].check<Int32Value>().value!!
96+
val arg1 = args[1].check<Int32Value>().value!!
97+
return int32Value(arg0 / arg1)
7598
}
7699
}
77100

@@ -89,8 +112,10 @@ internal object Fn_DIVIDE__INT64_INT64__INT64 : PartiQLFunction.Scalar {
89112
isNullable = false,
90113
)
91114

92-
override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
93-
TODO("Function divide not implemented")
115+
override fun invoke(args: Array<PartiQLValue>): Int64Value {
116+
val arg0 = args[0].check<Int64Value>().value!!
117+
val arg1 = args[1].check<Int64Value>().value!!
118+
return int64Value(arg0 / arg1)
94119
}
95120
}
96121

@@ -108,8 +133,10 @@ internal object Fn_DIVIDE__INT_INT__INT : PartiQLFunction.Scalar {
108133
isNullable = false,
109134
)
110135

111-
override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
112-
TODO("Function divide not implemented")
136+
override fun invoke(args: Array<PartiQLValue>): IntValue {
137+
val arg0 = args[0].check<IntValue>().value!!
138+
val arg1 = args[1].check<IntValue>().value!!
139+
return intValue(arg0 / arg1)
113140
}
114141
}
115142

@@ -127,8 +154,10 @@ internal object Fn_DIVIDE__DECIMAL_ARBITRARY_DECIMAL_ARBITRARY__DECIMAL_ARBITRAR
127154
isNullable = false,
128155
)
129156

130-
override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
131-
TODO("Function divide not implemented")
157+
override fun invoke(args: Array<PartiQLValue>): DecimalValue {
158+
val arg0 = args[0].check<DecimalValue>().value!!
159+
val arg1 = args[1].check<DecimalValue>().value!!
160+
return decimalValue(arg0 / arg1)
132161
}
133162
}
134163

@@ -146,8 +175,10 @@ internal object Fn_DIVIDE__FLOAT32_FLOAT32__FLOAT32 : PartiQLFunction.Scalar {
146175
isNullable = false,
147176
)
148177

149-
override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
150-
TODO("Function divide not implemented")
178+
override fun invoke(args: Array<PartiQLValue>): Float32Value {
179+
val arg0 = args[0].check<Float32Value>().value!!
180+
val arg1 = args[1].check<Float32Value>().value!!
181+
return float32Value(arg0 / arg1)
151182
}
152183
}
153184

@@ -165,7 +196,9 @@ internal object Fn_DIVIDE__FLOAT64_FLOAT64__FLOAT64 : PartiQLFunction.Scalar {
165196
isNullable = false,
166197
)
167198

168-
override fun invoke(args: Array<PartiQLValue>): PartiQLValue {
169-
TODO("Function divide not implemented")
199+
override fun invoke(args: Array<PartiQLValue>): Float64Value {
200+
val arg0 = args[0].check<Float64Value>().value!!
201+
val arg1 = args[1].check<Float64Value>().value!!
202+
return float64Value(arg0 / arg1)
170203
}
171204
}

0 commit comments

Comments
 (0)