Skip to content

Commit

Permalink
Added support for arrayFlatten
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonard Wolters committed Aug 29, 2023
1 parent aeefe33 commit b49b9f6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,13 @@ class ArrayFunctionsIT extends DslITSpec {
execute(select(ArrayLength(Array("1", "2")))).futureValue should be("2")
execute(select(arrayLength(Array("1", "2")))).futureValue should be("2")
}

it should "arrayFunction: flatten" in {
execute(select(ArrayFlatten(Array("1", "2")))).futureValue should be("['1','2']")
execute(select(ArrayFlatten(Array(Array("1"), Array("2"))))).futureValue should be("['1','2']")
execute(select(ArrayFlatten(Array(Array("1", "2"), Array("3", "4"))))).futureValue should be("['1','2','3','4']")
execute(select(ArrayFlatten(Array(Array(Array("1")), Array(Array("2"), Array("3", "4")))))).futureValue should be(
"['1','2','3','4']"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ trait ArrayFunctions { this: Magnets =>
case class ArrayEmpty(col: ArrayColMagnet[_]) extends ArrayFunctionOp[Boolean]
case class ArrayNotEmpty(col: ArrayColMagnet[_]) extends ArrayFunctionOp[Boolean]
case class ArrayLength(col: ArrayColMagnet[_]) extends ArrayFunctionOp[Long]
// now 23-08-29
case class ArrayFlatten[V](col1: ArrayColMagnet[V]) extends ArrayFunctionOp[Iterable[V]]

def emptyArrayUInt8: EmptyArrayUInt8 = EmptyArrayUInt8()
def emptyArrayUInt16: EmptyArrayUInt16 = EmptyArrayUInt16()
Expand Down Expand Up @@ -158,4 +160,6 @@ trait ArrayFunctions { this: Magnets =>

def arrayLength(col: ArrayColMagnet[_]): ArrayLength = ArrayLength(col)
def length(col: ArrayColMagnet[_]): ArrayLength = ArrayLength(col)

def flatten[_](col: ArrayColMagnet[_]): ArrayFlatten[_] = ArrayFlatten(col)
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ trait ArrayFunctionTokenizer { this: ClickhouseTokenizerModule =>
case ArrayEmpty(col: ArrayColMagnet[_]) => s"empty(${tokenizeColumn(col.column)})"
case ArrayNotEmpty(col: ArrayColMagnet[_]) => s"notEmpty(${tokenizeColumn(col.column)})"
case ArrayLength(col: ArrayColMagnet[_]) => s"length(${tokenizeColumn(col.column)})"
case ArrayFlatten(col: ArrayColMagnet[_]) => s"arrayFlatten(${tokenizeColumn(col.column)})"
}

protected def tokenizeArrayFunctionConst(col: ArrayFunctionConst[_])(implicit ctx: TokenizeContext): String =
Expand Down

0 comments on commit b49b9f6

Please sign in to comment.