Skip to content

Commit

Permalink
Updates Javadocs and straggling comments
Browse files Browse the repository at this point in the history
  • Loading branch information
johnedquinn committed Nov 25, 2024
1 parent 8443f33 commit ecbe859
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal val Agg_AVG__INT__INT = Aggregation.static(
internal val Agg_AVG__DECIMAL_ARBITRARY__DECIMAL_ARBITRARY = Aggregation.static(

name = "avg",
returns = PType.decimal(38, 19), // TODO
returns = PType.decimal(38, 19),
parameters = arrayOf(
@Suppress("DEPRECATION") Parameter("value", PType.decimal()),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ internal abstract class DiadicComparisonOperator(name: String) : DiadicOperator(
val hasDecimal = lhs.kind == PType.Kind.DECIMAL || rhs.kind == PType.Kind.DECIMAL
val allNumbers = (SqlTypeFamily.NUMBER.contains(lhs) && SqlTypeFamily.NUMBER.contains(rhs))
if (hasDecimal && allNumbers) {
return getAnyInstance(lhs, rhs)
return getNumberInstance(lhs, rhs)
}
return super.getInstance(args)
}

private fun getAnyInstance(lhs: PType, rhs: PType): Function.Instance {
private fun getNumberInstance(lhs: PType, rhs: PType): Function.Instance {
return basic(PType.bool(), lhs, rhs) { args ->
val l = args[0].getNumber()
val r = args[1].getNumber()
Datum.bool(getComparison(l, r))
Datum.bool(getNumberComparison(l, r))
}
}

abstract fun getComparison(lhs: Number, rhs: Number): Boolean
abstract fun getNumberComparison(lhs: Number, rhs: Number): Boolean

private fun Datum.getNumber(): Number {
return when (this.type.kind) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal object FnGt : DiadicComparisonOperator("gt") {
fillTable()
}

override fun getComparison(lhs: Number, rhs: Number): Boolean {
override fun getNumberComparison(lhs: Number, rhs: Number): Boolean {
return lhs > rhs
}

Expand Down Expand Up @@ -50,7 +50,7 @@ internal object FnGt : DiadicComparisonOperator("gt") {
}
}

// TODO: Update
// TODO: Update numeric to use bigDecimal rather than bigInteger.
override fun getNumericInstance(numericLhs: PType, numericRhs: PType): Function.Instance {
return basic(PType.bool(), PType.numeric()) { args ->
val lhs = args[0].bigInteger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal object FnGte : DiadicComparisonOperator("gte") {
fillTable()
}

override fun getComparison(lhs: Number, rhs: Number): Boolean {
override fun getNumberComparison(lhs: Number, rhs: Number): Boolean {
return lhs >= rhs
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal object FnLt : DiadicComparisonOperator("lt") {
}
}

override fun getComparison(lhs: Number, rhs: Number): Boolean {
override fun getNumberComparison(lhs: Number, rhs: Number): Boolean {
return lhs < rhs
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal object FnLte : DiadicComparisonOperator("lte") {
fillTable()
}

override fun getComparison(lhs: Number, rhs: Number): Boolean {
override fun getNumberComparison(lhs: Number, rhs: Number): Boolean {
return lhs <= rhs
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ internal object FnModulo : DiadicArithmeticOperator("modulo") {
}
}

// SQL:Server:
// p = p1 - s1 + s2 + max(6, s1 + p2 + 1)
// s = max(6, s1 + p2 + 1)
override fun getDecimalInstance(decimalLhs: PType, decimalRhs: PType): Function.Instance {
val p = decimalLhs.precision - decimalLhs.scale + decimalRhs.scale + Math.max(6, decimalLhs.scale + decimalRhs.precision + 1)
val s = Math.max(6, decimalLhs.scale + decimalRhs.precision + 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ internal object FnTimes : DiadicArithmeticOperator("times") {
}
}

// SQL Server:
// p = p1 + p2 + 1
// s = s1 + s2
override fun getDecimalInstance(decimalLhs: PType, decimalRhs: PType): Function.Instance {
val p = decimalLhs.precision + decimalRhs.precision + 1
val s = decimalLhs.scale + decimalRhs.scale
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ class DatumIonReader(
}
}

/**
* @param sourceDataFormat The source data format of the Ion data; if not specified, defaults to [SourceDataFormat.IonForPartiQL].
* @param ionReaderBuilder The builder for creating the [IonReader].
*/
public class DatumIonReaderBuilder private constructor(
private var sourceDataFormat: SourceDataFormat = SourceDataFormat.IonForPartiQL,
private var ionReaderBuilder: IonReaderBuilder,
Expand All @@ -338,6 +342,11 @@ public class DatumIonReaderBuilder private constructor(
}

public companion object {

/**
* Creates a [DatumIonReaderBuilder] with the default settings.
* The default source data format is [SourceDataFormat.IonForPartiQL] and the default [IonReaderBuilder] is [IonReaderBuilder.standard]
*/
@JvmStatic
public fun standard(): DatumIonReaderBuilder = DatumIonReaderBuilder(
sourceDataFormat = SourceDataFormat.IonForPartiQL,
Expand Down

0 comments on commit ecbe859

Please sign in to comment.