Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into feature/dope-215-refactor-tests
Browse files Browse the repository at this point in the history
# Conflicts:
#	core/src/test/kotlin/ch/ergon/dope/buildTest/NumberFunctionsTest.kt
  • Loading branch information
jansigi committed Jul 10, 2024
2 parents 5fdb5d4 + bed8845 commit 587992f
Show file tree
Hide file tree
Showing 51 changed files with 1,507 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package ch.ergon.dope.resolvable.clause

import ch.ergon.dope.resolvable.clause.model.DeleteLimitClause
import ch.ergon.dope.resolvable.clause.model.DeleteOffsetClause
import ch.ergon.dope.resolvable.clause.model.DeleteUseKeysArrayClause
import ch.ergon.dope.resolvable.clause.model.DeleteUseKeysStringClause
import ch.ergon.dope.resolvable.clause.model.DeleteUseKeysClause.Companion.DeleteUseKeysClause
import ch.ergon.dope.resolvable.clause.model.DeleteWhereClause
import ch.ergon.dope.resolvable.clause.model.ReturningClause
import ch.ergon.dope.resolvable.expression.TypeExpression
Expand Down Expand Up @@ -36,9 +35,10 @@ interface IDeleteUseKeysClause : IDeleteWhereClause {
}

interface IDeleteClause : IDeleteUseKeysClause {
fun useKeys(key: TypeExpression<StringType>) = DeleteUseKeysStringClause(key, this)
fun useKeys(key: TypeExpression<StringType>) = DeleteUseKeysClause(key, this)

// JvmName annotation in interfaces is currently not supported. https://youtrack.jetbrains.com/issue/KT-20068
@Suppress("INAPPLICABLE_JVM_NAME")
@JvmName("useKeysArray")
fun useKeys(key: TypeExpression<ArrayType<StringType>>) = DeleteUseKeysArrayClause(key, this)
fun useKeys(key: TypeExpression<ArrayType<StringType>>) = DeleteUseKeysClause(key, this)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import ch.ergon.dope.resolvable.clause.model.SelectLimitClause
import ch.ergon.dope.resolvable.clause.model.SelectOffsetClause
import ch.ergon.dope.resolvable.clause.model.SelectOrderByClause
import ch.ergon.dope.resolvable.clause.model.SelectOrderByTypeClause
import ch.ergon.dope.resolvable.clause.model.SelectUseKeysArrayClause
import ch.ergon.dope.resolvable.clause.model.SelectUseKeysStringClause
import ch.ergon.dope.resolvable.clause.model.SelectUseKeysClause.Companion.SelectUseKeysClause
import ch.ergon.dope.resolvable.clause.model.SelectWhereClause
import ch.ergon.dope.resolvable.clause.model.StandardJoinClause
import ch.ergon.dope.resolvable.clause.model.UnnestClause
Expand Down Expand Up @@ -57,11 +56,12 @@ interface ISelectUseKeysClause : ISelectWhereClause {
}

interface ISelectFromClause : ISelectUseKeysClause {
fun useKeys(key: TypeExpression<StringType>) = SelectUseKeysStringClause(key, this)
fun useKeys(key: TypeExpression<StringType>) = SelectUseKeysClause(key, this)

// JvmName annotation in interfaces is currently not supported. https://youtrack.jetbrains.com/issue/KT-20068
@Suppress("INAPPLICABLE_JVM_NAME")
@JvmName("useKeysArray")
fun useKeys(keys: TypeExpression<ArrayType<StringType>>) = SelectUseKeysArrayClause(keys, this)
fun useKeys(keys: TypeExpression<ArrayType<StringType>>) = SelectUseKeysClause(keys, this)
}

interface ISelectJoinClause : ISelectFromClause {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,66 @@ import ch.ergon.dope.validtype.ValidType

private const val USE_KEYS = "USE KEYS"

sealed class SelectUseKeysClause(
private val parentClause: ISelectFromClause,
private val keys: TypeExpression<out ValidType>,
) : ISelectUseKeysClause {
class SelectUseKeysClause : ISelectUseKeysClause {
private lateinit var useKeys: TypeExpression<out ValidType>
private lateinit var parentClause: ISelectFromClause

companion object {
@JvmName("selectSingleUseKeysClauseConstructor")
fun SelectUseKeysClause(key: TypeExpression<StringType>, parentClause: ISelectFromClause): SelectUseKeysClause {
val instance = SelectUseKeysClause()
instance.useKeys = key
instance.parentClause = parentClause
return instance
}

@JvmName("selectMultipleUseKeysClauseConstructor")
fun SelectUseKeysClause(keys: TypeExpression<ArrayType<StringType>>, parentClause: ISelectFromClause): SelectUseKeysClause {
val instance = SelectUseKeysClause()
instance.useKeys = keys
instance.parentClause = parentClause
return instance
}
}

override fun toDopeQuery(): DopeQuery {
val parentDopeQuery = parentClause.toDopeQuery()
val keysDopeQuery = keys.toDopeQuery()
val keysDopeQuery = useKeys.toDopeQuery()
return DopeQuery(
queryString = formatToQueryStringWithSymbol(parentDopeQuery.queryString, USE_KEYS, keysDopeQuery.queryString),
parameters = parentDopeQuery.parameters + keysDopeQuery.parameters,
)
}
}

class SelectUseKeysStringClause(key: TypeExpression<StringType>, parentClause: ISelectFromClause) :
SelectUseKeysClause(parentClause, key)
class DeleteUseKeysClause : IDeleteUseKeysClause {
private lateinit var useKeys: TypeExpression<out ValidType>
private lateinit var parentClause: IDeleteClause

class SelectUseKeysArrayClause(keys: TypeExpression<ArrayType<StringType>>, parentClause: ISelectFromClause) :
SelectUseKeysClause(parentClause, keys)
companion object {
@JvmName("deleteSingleUseKeysClauseConstructor")
fun DeleteUseKeysClause(key: TypeExpression<StringType>, parentClause: IDeleteClause): DeleteUseKeysClause {
val instance = DeleteUseKeysClause()
instance.useKeys = key
instance.parentClause = parentClause
return instance
}

@JvmName("deleteMultipleUseKeysClauseConstructor")
fun DeleteUseKeysClause(keys: TypeExpression<ArrayType<StringType>>, parentClause: IDeleteClause): DeleteUseKeysClause {
val instance = DeleteUseKeysClause()
instance.useKeys = keys
instance.parentClause = parentClause
return instance
}
}

sealed class DeleteUseKeysClause(
private val parentClause: IDeleteClause,
private val keys: TypeExpression<out ValidType>,
) : IDeleteUseKeysClause {
override fun toDopeQuery(): DopeQuery {
val parentDopeQuery = parentClause.toDopeQuery()
val keysDopeQuery = keys.toDopeQuery()
val keysDopeQuery = useKeys.toDopeQuery()
return DopeQuery(
queryString = formatToQueryStringWithSymbol(parentDopeQuery.queryString, USE_KEYS, keysDopeQuery.queryString),
parameters = parentDopeQuery.parameters + keysDopeQuery.parameters,
)
}
}

class DeleteUseKeysStringClause(key: TypeExpression<StringType>, parentClause: IDeleteClause) :
DeleteUseKeysClause(parentClause, key)

class DeleteUseKeysArrayClause(keys: TypeExpression<ArrayType<StringType>>, parentClause: IDeleteClause) :
DeleteUseKeysClause(parentClause, keys)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ch.ergon.dope.resolvable.expression.unaliased.type.numeric

import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import ch.ergon.dope.validtype.NumberType

class AbsoluteExpression(value: TypeExpression<NumberType>) : NumberFunctionExpression("ABS", value)

fun abs(value: TypeExpression<NumberType>) = AbsoluteExpression(value)

fun abs(value: Number) = abs(value.toDopeType())
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ch.ergon.dope.resolvable.expression.unaliased.type.numeric

import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import ch.ergon.dope.validtype.NumberType

class ArcCosineExpression(value: TypeExpression<NumberType>) : NumberFunctionExpression("ACOS", value)

fun acos(value: TypeExpression<NumberType>) = ArcCosineExpression(value)

fun acos(value: Number) = acos(value.toDopeType())
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ch.ergon.dope.resolvable.expression.unaliased.type.numeric

import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import ch.ergon.dope.validtype.NumberType

class ArcSineExpression(value: TypeExpression<NumberType>) : NumberFunctionExpression("ASIN", value)

fun asin(value: TypeExpression<NumberType>) = ArcSineExpression(value)

fun asin(value: Number) = asin(value.toDopeType())
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ch.ergon.dope.resolvable.expression.unaliased.type.numeric

import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import ch.ergon.dope.validtype.NumberType

class ArcTangent2Expression(divisor: TypeExpression<NumberType>, dividend: TypeExpression<NumberType>) :
NumberFunctionExpression("ATAN2", divisor, dividend)

fun atan2(divisor: TypeExpression<NumberType>, dividend: TypeExpression<NumberType>) = ArcTangent2Expression(divisor, dividend)

fun atan2(divisor: TypeExpression<NumberType>, dividend: Number) = atan2(divisor, dividend.toDopeType())

fun atan2(divisor: Number, dividend: TypeExpression<NumberType>) = atan2(divisor.toDopeType(), dividend)

fun atan2(divisor: Number, dividend: Number) = atan2(divisor.toDopeType(), dividend.toDopeType())
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ch.ergon.dope.resolvable.expression.unaliased.type.numeric

import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import ch.ergon.dope.validtype.NumberType

class ArcTangentExpression(value: TypeExpression<NumberType>) : NumberFunctionExpression("ATAN", value)

fun atan(value: TypeExpression<NumberType>) = ArcTangentExpression(value)

fun atan(value: Number) = atan(value.toDopeType())
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ch.ergon.dope.resolvable.expression.unaliased.type.numeric

import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import ch.ergon.dope.validtype.NumberType

class CeilingExpression(value: TypeExpression<NumberType>) : NumberFunctionExpression("CEIL", value)

fun ceil(value: TypeExpression<NumberType>) = CeilingExpression(value)

fun ceil(value: Number) = ceil(value.toDopeType())
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ch.ergon.dope.resolvable.expression.unaliased.type.numeric

import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import ch.ergon.dope.validtype.NumberType

class CosineExpression(value: TypeExpression<NumberType>) : NumberFunctionExpression("COS", value)

fun cos(value: TypeExpression<NumberType>) = CosineExpression(value)

fun cos(value: Number) = cos(value.toDopeType())
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ch.ergon.dope.resolvable.expression.unaliased.type.numeric

import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import ch.ergon.dope.validtype.NumberType

class DegreesExpression(value: TypeExpression<NumberType>) : NumberFunctionExpression("DEGREES", value)

fun degrees(value: TypeExpression<NumberType>) = DegreesExpression(value)

fun degrees(value: Number) = degrees(value.toDopeType())
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ch.ergon.dope.resolvable.expression.unaliased.type.numeric

import ch.ergon.dope.DopeQuery
import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.validtype.NumberType

class EulerExpression : TypeExpression<NumberType> {
override fun toDopeQuery() = DopeQuery(
queryString = "E()",
parameters = emptyMap(),
)
}

fun e() = EulerExpression()
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ch.ergon.dope.resolvable.expression.unaliased.type.numeric

import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import ch.ergon.dope.validtype.NumberType

class ExponentExpression(value: TypeExpression<NumberType>) : NumberFunctionExpression("EXP", value)

fun exp(value: TypeExpression<NumberType>) = ExponentExpression(value)

fun exp(value: Number) = exp(value.toDopeType())
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ch.ergon.dope.resolvable.expression.unaliased.type.numeric

import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import ch.ergon.dope.validtype.NumberType

class FloorExpression(value: TypeExpression<NumberType>) : NumberFunctionExpression("FLOOR", value)

fun floor(value: TypeExpression<NumberType>) = FloorExpression(value)

fun floor(value: Number) = floor(value.toDopeType())
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ch.ergon.dope.resolvable.expression.unaliased.type.numeric

import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import ch.ergon.dope.validtype.NumberType

class LogExpression(value: TypeExpression<NumberType>) : NumberFunctionExpression("LOG", value)

fun log(value: TypeExpression<NumberType>) = LogExpression(value)

fun log(value: Number) = log(value.toDopeType())
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ch.ergon.dope.resolvable.expression.unaliased.type.numeric

import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import ch.ergon.dope.validtype.NumberType

class LogNaturalisExpression(value: TypeExpression<NumberType>) : NumberFunctionExpression("LN", value)

fun ln(value: TypeExpression<NumberType>) = LogNaturalisExpression(value)

fun ln(value: Number) = ln(value.toDopeType())
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ch.ergon.dope.resolvable.expression.unaliased.type.numeric

import ch.ergon.dope.DopeQuery
import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.operator.FunctionOperator
import ch.ergon.dope.validtype.NumberType

sealed class NumberFunctionExpression(
private val symbol: String,
private val value: TypeExpression<NumberType>,
private val extraValue: TypeExpression<NumberType>? = null,
) : TypeExpression<NumberType>, FunctionOperator {
override fun toDopeQuery(): DopeQuery {
val valueDopeQuery = value.toDopeQuery()
val extraValueDopeQuery = extraValue?.toDopeQuery()
return DopeQuery(
queryString = toFunctionQueryString(symbol = symbol, valueDopeQuery, extra = extraValueDopeQuery),
parameters = valueDopeQuery.parameters + extraValueDopeQuery?.parameters.orEmpty(),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ch.ergon.dope.resolvable.expression.unaliased.type.numeric

import ch.ergon.dope.DopeQuery
import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.validtype.NumberType

class PiExpression : TypeExpression<NumberType> {
override fun toDopeQuery() = DopeQuery(
queryString = "PI()",
parameters = emptyMap(),
)
}

fun pi() = PiExpression()
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ch.ergon.dope.resolvable.expression.unaliased.type.numeric

import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import ch.ergon.dope.validtype.NumberType

class PowerExpression(base: TypeExpression<NumberType>, exponent: TypeExpression<NumberType>) :
NumberFunctionExpression("POWER", base, exponent)

fun power(base: TypeExpression<NumberType>, exponent: TypeExpression<NumberType>) = PowerExpression(base, exponent)

fun power(base: TypeExpression<NumberType>, exponent: Number) = power(base, exponent.toDopeType())

fun power(base: Number, exponent: TypeExpression<NumberType>) = power(base.toDopeType(), exponent)

fun power(base: Number, exponent: Number) = power(base.toDopeType(), exponent.toDopeType())
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ch.ergon.dope.resolvable.expression.unaliased.type.numeric

import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import ch.ergon.dope.validtype.NumberType

class RadiansExpression(value: TypeExpression<NumberType>) : NumberFunctionExpression("RADIANS", value)

fun radians(value: TypeExpression<NumberType>) = RadiansExpression(value)

fun radians(value: Number) = radians(value.toDopeType())
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ch.ergon.dope.resolvable.expression.unaliased.type.numeric

import ch.ergon.dope.DopeQuery
import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import ch.ergon.dope.resolvable.operator.FunctionOperator
import ch.ergon.dope.validtype.NumberType

class RandomExpression(private val value: TypeExpression<NumberType>? = null) :
TypeExpression<NumberType>, FunctionOperator {
override fun toDopeQuery() =
value?.let {
val valueDopeQuery = value.toDopeQuery()
DopeQuery(
queryString = toFunctionQueryString("RANDOM", valueDopeQuery.queryString),
parameters = valueDopeQuery.parameters,
)
} ?: DopeQuery(queryString = "RANDOM()", parameters = emptyMap())
}

fun random() = RandomExpression()

fun random(value: TypeExpression<NumberType>) = RandomExpression(value)

fun random(value: Number) = random(value.toDopeType())
Loading

0 comments on commit 587992f

Please sign in to comment.