Skip to content
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

Scala 3 migration #158

Merged
merged 44 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
6c9732d
Scala 3 migration
aShevc Mar 12, 2024
b246813
Scala 3 migration
aShevc Mar 12, 2024
01a365a
More adjustments
aShevc Mar 13, 2024
27681e3
Compilation fix WIP
aShevc Mar 14, 2024
1e1d811
Merge remote-tracking branch 'origin/ashevc/scala-3-cross-compile' in…
aShevc Mar 14, 2024
e78ee68
tests fix driveby
aShevc Mar 14, 2024
42c9086
Final fix
aShevc Mar 14, 2024
fa69d6e
fixes
aShevc Mar 14, 2024
5eac23a
revert tests
aShevc Mar 14, 2024
0ec2d27
Added 3.3.1 Scala support for CI
aShevc Mar 14, 2024
9f12d84
Compilation fix
aShevc Mar 14, 2024
7532d9d
tests fix driveby
aShevc Mar 14, 2024
1180a0e
tests fix driveby
aShevc Mar 14, 2024
d031de8
tests fix driveby
aShevc Mar 14, 2024
4387a82
tests fix driveby
aShevc Mar 14, 2024
a9c36aa
tests fix driveby
aShevc Mar 14, 2024
6916683
tests fix driveby
aShevc Mar 14, 2024
b7b657d
tests fix driveby
aShevc Mar 14, 2024
5e03424
tests fix driveby
aShevc Mar 14, 2024
ee7ba6a
tests fix driveby
aShevc Mar 14, 2024
7eb4f48
tests fix driveby
aShevc Mar 14, 2024
c2167dd
tests fix driveby
aShevc Mar 14, 2024
f27b252
tests fix driveby
aShevc Mar 14, 2024
83a1f85
tests fix driveby
aShevc Mar 14, 2024
ec1137e
tests fix driveby
aShevc Mar 14, 2024
0f1b2da
tests fix driveby
aShevc Mar 14, 2024
d2e76a5
tests fix driveby
aShevc Mar 14, 2024
3c9e18e
tests fix driveby
aShevc Mar 14, 2024
5ad2e90
tests fix driveby
aShevc Mar 14, 2024
2454680
THis fixes it
aShevc Mar 14, 2024
f8b26d9
test conv
aShevc Mar 15, 2024
48fc216
Test fix
aShevc Mar 15, 2024
a877a00
tests fix driveby
aShevc Mar 15, 2024
c0ad380
more fixes
aShevc Mar 15, 2024
fe29763
Fix ins
aShevc Mar 15, 2024
532e9b0
fix
aShevc Mar 15, 2024
ad6dfbc
Fixes
aShevc Mar 15, 2024
5cd4cd3
test
aShevc Mar 15, 2024
22896ff
Scala version update
aShevc Mar 15, 2024
005f235
Addressed comments
Mar 19, 2024
f1b6951
Fixed Scala 2 version in Ci/CD
Mar 20, 2024
b9c6e14
test
Mar 20, 2024
c9c7cb4
fix
Mar 20, 2024
f58113a
test fix
Mar 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
scala: [2.13.8]
scala: [2.13.8, 3.3.1]
java: [temurin@17]
clickhouse: [21.3, 21.8.14, 22.3]
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.8]
scala: [2.13.13, 3.3.1]
java: [temurin@17]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -110,12 +110,22 @@ jobs:
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Download target directories (2.13.8)
- name: Download target directories (3.3.1)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-2.13.8-${{ matrix.java }}
name: target-${{ matrix.os }}-3.3.1-${{ matrix.java }}

- name: Inflate target directories (2.13.8)
- name: Inflate target directories (3.3.1)
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.13.13)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-2.13.13-${{ matrix.java }}

- name: Inflate target directories (2.13.13)
run: |
tar xf targets.tar
rm targets.tar
Expand Down
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ lazy val root = (project in file("."))
inThisBuild(
List(
organization := "com.crobox.clickhouse",
scalaVersion := "2.13.8",
crossScalaVersions := List("2.13.8"),
scalaVersion := "2.13.13",
crossScalaVersions := List("2.13.13", "3.3.1"),
javacOptions ++= Seq("-g", "-Xlint:unchecked", "-Xlint:deprecation", "-source", "11", "-target", "11"),
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature", "-language:_", "-encoding", "UTF-8"),
publishTo := {
Expand Down
53 changes: 53 additions & 0 deletions dsl/src/it/scala-2/com/crobox/clickhouse/dsl/QueryITTypeCast.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.crobox.clickhouse.dsl

import com.crobox.clickhouse.DslITSpec
class QueryITTypeCast extends DslITSpec {

// This test uses extension methods removed in Scala 3. Hence only making it available for Scala 2
it should "perform typecasts" in {

type TakeIntGiveIntTypes = Column => (TypeCastColumn[T] with Reinterpretable) forSome {
type T >: Long with String with Float with Serializable
}

val takeIntGiveIntCast = Set(
toUInt8 _,
toUInt16 _,
toUInt32 _,
toUInt64 _,
toInt8 _,
toInt16 _,
toInt32 _,
toInt64 _,
toFloat32 _,
toFloat64 _
)

val takeIntGiveStringCast = Set(
toDate _,
toDateTime _,
toStringRep _
)

val reinterpToIntCast = takeIntGiveIntCast

val reinterpToStringCast = Set(
toStringRep _
)

val takeStringGiveIntCast = Set(
toUInt8OrZero _,
toUInt16OrZero _,
toUInt32OrZero _,
toUInt64OrZero _,
toInt8OrZero _,
toInt16OrZero _,
toInt32OrZero _,
toInt64OrZero _,
toFloat32OrZero _,
toFloat64OrZero _,
(col: TableColumn[_]) => toFixedString(col, 10),
toStringCutToZero _
)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.crobox.clickhouse.dsl

import com.crobox.clickhouse.DslITSpec
import com.crobox.clickhouse.{ClickhouseClient, DslITSpec}
import com.crobox.clickhouse.dsl.execution.QueryResult
import com.crobox.clickhouse.dsl.marshalling.ClickhouseJsonSupport._
import com.crobox.clickhouse.time.{IntervalStart, MultiDuration, MultiInterval, TimeUnit, TotalDuration}
import org.joda.time.{DateTime, DateTimeZone, Days}
import org.scalactic.TripleEqualsSupport
import org.scalatest.prop.TableDrivenPropertyChecks
import spray.json.RootJsonFormat

import java.util.UUID
import scala.concurrent.Future
Expand All @@ -17,10 +18,10 @@ class ClickhouseTimeSeriesIT extends DslITSpec with TableDrivenPropertyChecks {
case class CustomResult(time: IntervalStart, shields: String)

object CustomResult {
implicit val format = jsonFormat2(CustomResult.apply)
implicit val format: RootJsonFormat[CustomResult] = jsonFormat2(CustomResult.apply)
}

implicit val clickhouseClient = clickClient
implicit val clickhouseClient: ClickhouseClient = clickClient
val startInterval = DateTime.parse("2019-03-01").withTimeAtStartOfDay().withZone(DateTimeZone.UTC)
val secondsId = UUID.randomUUID()
val dayId = UUID.randomUUID()
Expand Down
47 changes: 0 additions & 47 deletions dsl/src/it/scala/com/crobox/clickhouse/dsl/QueryIT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,53 +30,6 @@ class QueryIT extends DslITSpec {
results.futureValue.rows.map(_.empty).head should be(1)
}

it should "perform typecasts" in {

type TakeIntGiveIntTypes = Column => (TypeCastColumn[_$1] with Reinterpretable) forSome {
type _$1 >: Long with String with Float with Serializable
}

val takeIntGiveIntCast = Set(
toUInt8 _,
toUInt16 _,
toUInt32 _,
toUInt64 _,
toInt8 _,
toInt16 _,
toInt32 _,
toInt64 _,
toFloat32 _,
toFloat64 _
)

val takeIntGiveStringCast = Set(
toDate _,
toDateTime _,
toStringRep _
)

val reinterpToIntCast = takeIntGiveIntCast

val reinterpToStringCast = Set(
toStringRep _
)

val takeStringGiveIntCast = Set(
toUInt8OrZero _,
toUInt16OrZero _,
toUInt32OrZero _,
toUInt64OrZero _,
toInt8OrZero _,
toInt16OrZero _,
toInt32OrZero _,
toInt64OrZero _,
toFloat32OrZero _,
toFloat64OrZero _,
(col: TableColumn[_]) => toFixedString(col, 10),
toStringCutToZero _
)
}

def runQry(query: OperationalQuery): Future[String] = {
val che = queryExecutor.asInstanceOf[DefaultClickhouseQueryExecutor]
clickhouseClient.query(che.toSql(query.internalQuery))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class ComparisonFunctionsIT extends DslITSpec {
r(someNum >= 3) shouldBe "1"
r(someNum <= 3) shouldBe "0"
r(someNum isEq 3) shouldBe "0"
r(someNum === 3) shouldBe "0"
r(someNum !== 3) shouldBe "1"
r(notEquals(1,2)) shouldBe "1"
r(_equals(2L,2)) shouldBe "1"
r(less(1.0,200)) shouldBe "1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.crobox.clickhouse.dsl.column
import com.crobox.clickhouse.DslITSpec
import com.crobox.clickhouse.dsl.misc.LogicalOperatorImprovements.ExpressionColumnImpr
import com.crobox.clickhouse.dsl.select
import com.crobox.clickhouse.dsl._
import scala.language.implicitConversions

import java.util.UUID

Expand All @@ -21,9 +23,15 @@ class INFunctionsIT extends DslITSpec {
Table3Entry(UUID.randomUUID(), 2, Option("b"), "c", "c")
)

// TODO: Temporary Scala 3 Workaround. Somehow in CI/CD version of Scala 3, columns are not converted to respectible
// Magnet instances, so that `in` method could be used. Need to explicitly specify type annotation for conversion to
// work. This may require more deep work on this in the future
private val constCol4: ConstOrColMagnet[String] = col4
private val constCol2: ConstOrColMagnet[Int] = col2

it should "use tableAlias for IN, single table" in {
execute(
select(col4).from(TwoTestTable).where(col4.in(select(col4).from(ThreeTestTable)))
select(col4).from(TwoTestTable).where(constCol4.in(select(col4).from(ThreeTestTable)))
).futureValue should be("a\nb")
}

Expand All @@ -35,9 +43,9 @@ class INFunctionsIT extends DslITSpec {
select(col4)
.from(TwoTestTable)
.where(
col4.in(select(col4).from(ThreeTestTable)) and
col2.in(select(col2).from(TwoTestTable)) and
col2.in(select(col4).from(ThreeTestTable))
constCol4.in(select(col4).from(ThreeTestTable)) and
constCol2.in(select(col2).from(TwoTestTable)) and
constCol2.in(select(col4).from(ThreeTestTable))
)
).futureValue should be("")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class NumericColFunctionIT extends DslITSpec {
it should "have correct types so reduce can be used" in {
val exp = Seq(
Const(true),
2 === 2,
3 === 3
2 isEq 2,
3 isEq 3
).reduce(_ or _)

toSql(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ object JoinQuery {
case class JoinQuery(joinType: JoinType,
other: FromQuery,
on: Seq[JoinCondition] = Seq.empty,
using: Seq[Column] = Seq.empty,
`using`: Seq[Column] = Seq.empty,
global: Boolean = false)

case class JoinCondition(left: Column, operator: String, right: Column) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ trait OperationalQuery extends Query {
OperationalQuery(
internalQuery.from
.map {
case query: InnerFromQuery => internalQuery.copy(from = Some(query.copy(alias = Option(alias))))
case query: InnerFromQuery => internalQuery.copy(from = Some(query.copy(alias = Option(alias))))
case table: TableFromQuery[_] => internalQuery.copy(from = Some(table.copy(alias = Option(alias))))
}
.getOrElse(internalQuery)
Expand Down Expand Up @@ -72,8 +72,8 @@ trait OperationalQuery extends Query {

def groupBy(columns: Column*): OperationalQuery = {
val internalGroupBy = internalQuery.groupBy.getOrElse(GroupByQuery())
val newGroupBy = Some(internalGroupBy.copy(usingColumns = internalGroupBy.usingColumns ++ columns))
aShevc marked this conversation as resolved.
Show resolved Hide resolved
val newSelect = mergeOperationalColumns(columns)
val newGroupBy = Some(internalGroupBy.copy(usingColumns = internalGroupBy.usingColumns ++ columns))
val newSelect = mergeOperationalColumns(columns)
OperationalQuery(
internalQuery.copy(select = newSelect, groupBy = newGroupBy)
)
Expand Down Expand Up @@ -122,7 +122,7 @@ trait OperationalQuery extends Query {

def unionAll(otherQuery: OperationalQuery): OperationalQuery = {
require(internalQuery.select.isDefined && otherQuery.internalQuery.select.isDefined,
"Trying to apply UNION ALL on non SELECT queries.")
"Trying to apply UNION ALL on non SELECT queries.")
require(
otherQuery.internalQuery.select.get.columns.size == internalQuery.select.get.columns.size,
"SELECT queries needs to have the same number of columns to perform UNION ALL."
Expand All @@ -146,7 +146,7 @@ trait OperationalQuery extends Query {
val filteredDuplicates = filteredSelectAll.filterNot(column => {
selectForGroupCols.exists {
case c: Column => column.name == c.name
case _ => false
case _ => false
}
})

Expand Down Expand Up @@ -225,12 +225,12 @@ trait OperationalQuery extends Query {
globalJoin(JoinQuery.AnyRightJoin, query)

def using(
column: Column,
columns: Column*
): OperationalQuery = {
column: Column,
columns: Column*
): OperationalQuery = {
require(internalQuery.join.isDefined)

val newJoin = this.internalQuery.join.get.copy(using = (column +: columns).distinct)
val newJoin = this.internalQuery.join.get.copy(`using` = (column +: columns).distinct)
OperationalQuery(internalQuery.copy(join = Some(newJoin)))
}

Expand Down
2 changes: 1 addition & 1 deletion dsl/src/main/scala/com/crobox/clickhouse/dsl/Query.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.crobox.clickhouse.dsl
import scala.util.Try

trait Table {
val database: String
def database: String = ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why did you instantiate this to an empty string? In the previous scenario compile errors would popup if not set. Now there might be a chance that an empty database is selected (which should be avoided imho)

val name: String
lazy val quoted: String =
s"${ClickhouseStatement.quoteIdentifier(database)}.${ClickhouseStatement.quoteIdentifier(name)}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.crobox.clickhouse.dsl.column

import com.crobox.clickhouse.dsl.{EmptyColumn, ExpressionColumn, TableColumn}
import org.joda.time.{DateTime, LocalDate}
import scala.language.implicitConversions

trait ArithmeticFunctions { self: Magnets =>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,20 @@ package com.crobox.clickhouse.dsl.column

import com.crobox.clickhouse.dsl.{EmptyColumn, ExpressionColumn}

trait ComparisonFunctions { self: Magnets =>
trait ComparisonFunctions {
self: Magnets =>

case class ComparisonColumn(left: Magnet[_], operator: String, right: Magnet[_]) extends ExpressionColumn[Boolean](EmptyColumn)

trait ComparableWith[M <: Magnet[_]] { self: Magnet[_] =>
def <(other: M): ExpressionColumn[Boolean] = ComparisonColumn(self, "<", other)
def >(other: M): ExpressionColumn[Boolean] = ComparisonColumn(self, ">", other)
def <>(other: M): ExpressionColumn[Boolean] = ComparisonColumn(self, "!=", other)
def isEq(other: M): ExpressionColumn[Boolean] = ComparisonColumn(self, "=", other)
def notEq(other: M): ExpressionColumn[Boolean] = ComparisonColumn(self, "!=", other)
def ===(other: M): ExpressionColumn[Boolean] = ComparisonColumn(self, "=", other)
def !==(other: M): ExpressionColumn[Boolean] = ComparisonColumn(self, "!=", other)
def <=(other: M): ExpressionColumn[Boolean] = ComparisonColumn(self, "<=", other)
def >=(other: M): ExpressionColumn[Boolean] = ComparisonColumn(self, ">=", other)
}

def _equals(col1: ConstOrColMagnet[_], col2: ConstOrColMagnet[_]): ExpressionColumn[Boolean] = ComparisonColumn(col1 , "=", col2)
def notEquals(col1: ConstOrColMagnet[_], col2: ConstOrColMagnet[_]): ExpressionColumn[Boolean] = ComparisonColumn(col1 , "!=", col2)
def less(col1: ConstOrColMagnet[_], col2: ConstOrColMagnet[_]): ExpressionColumn[Boolean] = ComparisonColumn(col1 , "<", col2)
def greater(col1: ConstOrColMagnet[_], col2: ConstOrColMagnet[_]): ExpressionColumn[Boolean] = ComparisonColumn(col1 , ">", col2)
def lessOrEquals(col1: ConstOrColMagnet[_], col2: ConstOrColMagnet[_]): ExpressionColumn[Boolean] = ComparisonColumn(col1 , "<=", col2)
def greaterOrEquals(col1: ConstOrColMagnet[_], col2: ConstOrColMagnet[_]): ExpressionColumn[Boolean] = ComparisonColumn(col1 , ">=", col2)
def _equals(col1: ConstOrColMagnet[_], col2: ConstOrColMagnet[_]): ExpressionColumn[Boolean] = ComparisonColumn(col1, "=", col2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't like the _ (which was already there btw). Can't we get rid of it? Or make this one deprecated and add the 'equals()' method. If compiler starts complaining, perhaps rename it to: 'isEquals' or something similar?


def notEquals(col1: ConstOrColMagnet[_], col2: ConstOrColMagnet[_]): ExpressionColumn[Boolean] = ComparisonColumn(col1, "!=", col2)

def less(col1: ConstOrColMagnet[_], col2: ConstOrColMagnet[_]): ExpressionColumn[Boolean] = ComparisonColumn(col1, "<", col2)

def greater(col1: ConstOrColMagnet[_], col2: ConstOrColMagnet[_]): ExpressionColumn[Boolean] = ComparisonColumn(col1, ">", col2)

def lessOrEquals(col1: ConstOrColMagnet[_], col2: ConstOrColMagnet[_]): ExpressionColumn[Boolean] = ComparisonColumn(col1, "<=", col2)

def greaterOrEquals(col1: ConstOrColMagnet[_], col2: ConstOrColMagnet[_]): ExpressionColumn[Boolean] = ComparisonColumn(col1, ">=", col2)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.crobox.clickhouse.dsl.column

import com.crobox.clickhouse.dsl.{Const, EmptyColumn, ExpressionColumn}
import com.crobox.clickhouse.dsl.marshalling.QueryValueFormats._

trait InFunctions { self: Magnets =>

Expand Down
Loading
Loading