-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6285 from TouK/ignite-problem-backport
[NU-1721] Fix for DatabaseLookupEnricher mixing fields values when it is connected to ignite db, backport of pr #6264
- Loading branch information
Showing
15 changed files
with
367 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...ts/sql/src/test/scala/pl/touk/nussknacker/sql/service/DatabaseQueryEnricherHsqlTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package pl.touk.nussknacker.sql.service | ||
|
||
import pl.touk.nussknacker.engine.api.typed.TypedMap | ||
import pl.touk.nussknacker.sql.db.schema.{MetaDataProviderFactory, TableDefinition} | ||
import pl.touk.nussknacker.sql.utils.BaseHsqlQueryEnricherTest | ||
import org.scalatest.BeforeAndAfterEach | ||
|
||
class DatabaseQueryEnricherHsqlTest | ||
extends BaseHsqlQueryEnricherTest | ||
with DatabaseQueryEnricherQueryWithEnricher | ||
with BeforeAndAfterEach { | ||
|
||
override val service = | ||
new DatabaseQueryEnricher(hsqlDbPoolConfig, new MetaDataProviderFactory().create(hsqlDbPoolConfig)) | ||
|
||
override val prepareHsqlDDLs: List[String] = List( | ||
"CREATE TABLE people (id INT, name VARCHAR(40));", | ||
"INSERT INTO people (id, name) VALUES (1, 'John')" | ||
) | ||
|
||
override protected def afterEach(): Unit = { | ||
val cleanupStatements = List( | ||
"TRUNCATE TABLE people;", | ||
"INSERT INTO people (id, name) VALUES (1, 'John')" | ||
) | ||
cleanupStatements.foreach { ddlStr => | ||
val ddlStatement = conn.prepareStatement(ddlStr) | ||
try ddlStatement.execute() | ||
finally ddlStatement.close() | ||
} | ||
} | ||
|
||
test("DatabaseQueryEnricher#implementation without cache") { | ||
val result = queryWithEnricher( | ||
"select * from people where id = ?", | ||
Map("arg1" -> 1.asInstanceOf[AnyRef]), | ||
conn, | ||
service, | ||
"List[Record{ID: Integer, NAME: String}]" | ||
) | ||
result shouldBe List( | ||
TypedMap(Map("ID" -> 1, "NAME" -> "John")) | ||
) | ||
} | ||
|
||
test("DatabaseQueryEnricher#implementation without cache and with mixed lowercase and uppercase characters") { | ||
val result = queryWithEnricher( | ||
"select iD, NaMe from people where id = ?", | ||
Map("arg1" -> 1.asInstanceOf[AnyRef]), | ||
conn, | ||
service, | ||
"List[Record{ID: Integer, NAME: String}]" | ||
) | ||
result shouldBe List( | ||
TypedMap(Map("NAME" -> "John", "ID" -> 1)) | ||
) | ||
} | ||
|
||
test("DatabaseQueryEnricher#implementation update query") { | ||
val query = "UPDATE people SET name = 'Don' where id = ?" | ||
updateWithEnricher(query, conn, Map("arg1" -> 1.asInstanceOf[AnyRef]), service) | ||
|
||
val queryResultSet = conn.prepareStatement("SELECT * FROM people WHERE id = 1").executeQuery() | ||
queryResultSet.next() | ||
queryResultSet.getObject("name") shouldBe "Don" | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
.../src/test/scala/pl/touk/nussknacker/sql/service/DatabaseQueryEnricherPostgresqlTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package pl.touk.nussknacker.sql.service | ||
|
||
import org.scalatest.BeforeAndAfterEach | ||
import pl.touk.nussknacker.engine.api.typed.TypedMap | ||
import pl.touk.nussknacker.sql.db.schema.{MetaDataProviderFactory, TableDefinition} | ||
import pl.touk.nussknacker.sql.utils.BasePostgresqlQueryEnricherTest | ||
|
||
class DatabaseQueryEnricherPostgresqlTest | ||
extends BasePostgresqlQueryEnricherTest | ||
with DatabaseQueryEnricherQueryWithEnricher | ||
with BeforeAndAfterEach { | ||
|
||
override val service = | ||
new DatabaseQueryEnricher(postgresqlDbPoolConfig, new MetaDataProviderFactory().create(postgresqlDbPoolConfig)) | ||
|
||
override val preparePostgresqlDDLs: List[String] = List( | ||
"CREATE TABLE people (id INT, name VARCHAR(40));", | ||
"INSERT INTO people (id, name) VALUES (1, 'John')" | ||
) | ||
|
||
override protected def afterEach(): Unit = { | ||
val cleanupStatements = List( | ||
"TRUNCATE TABLE people;", | ||
"INSERT INTO people (id, name) VALUES (1, 'John')" | ||
) | ||
cleanupStatements.foreach { ddlStr => | ||
val ddlStatement = conn.prepareStatement(ddlStr) | ||
try ddlStatement.execute() | ||
finally ddlStatement.close() | ||
} | ||
} | ||
|
||
test("DatabaseQueryEnricherPostgresqlTest#implementation without cache") { | ||
val result = queryWithEnricher( | ||
"select * from people where id = ?", | ||
Map("arg1" -> 1.asInstanceOf[AnyRef]), | ||
conn, | ||
service, | ||
"List[Record{id: Integer, name: String}]" | ||
) | ||
result shouldBe List( | ||
TypedMap(Map("name" -> "John", "id" -> 1)) | ||
) | ||
} | ||
|
||
test( | ||
"DatabaseQueryEnricherPostgresqlTest#implementation without cache and with mixed lowercase and uppercase characters" | ||
) { | ||
val result = queryWithEnricher( | ||
"select iD, NaMe from people where id = ?", | ||
Map("arg1" -> 1.asInstanceOf[AnyRef]), | ||
conn, | ||
service, | ||
"List[Record{id: Integer, name: String}]" | ||
) | ||
result shouldBe List( | ||
TypedMap(Map("name" -> "John", "id" -> 1)) | ||
) | ||
} | ||
|
||
test("DatabaseQueryEnricherPostgresqlTest#implementation update query") { | ||
val query = "UPDATE people SET name = 'Don' where id = ?" | ||
updateWithEnricher(query, conn, Map("arg1" -> 1.asInstanceOf[AnyRef]), service) | ||
|
||
val queryResultSet = conn.prepareStatement("SELECT * FROM people WHERE id = 1").executeQuery() | ||
queryResultSet.next() | ||
queryResultSet.getObject("name") shouldBe "Don" | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
...c/test/scala/pl/touk/nussknacker/sql/service/DatabaseQueryEnricherQueryWithEnricher.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package pl.touk.nussknacker.sql.service | ||
|
||
import pl.touk.nussknacker.engine.api.typed.TypedMap | ||
import pl.touk.nussknacker.sql.db.query.{ResultSetStrategy, UpdateResultStrategy} | ||
import pl.touk.nussknacker.sql.db.schema.TableDefinition | ||
import pl.touk.nussknacker.sql.utils.BaseDatabaseQueryEnricherTest | ||
|
||
import java.sql.Connection | ||
import scala.concurrent.Await | ||
|
||
trait DatabaseQueryEnricherQueryWithEnricher extends BaseDatabaseQueryEnricherTest { | ||
|
||
import scala.concurrent.duration._ | ||
import scala.jdk.CollectionConverters._ | ||
|
||
def queryWithEnricher( | ||
query: String, | ||
parameters: Map[String, AnyRef], | ||
connection: Connection, | ||
databaseQueryEnricher: DatabaseQueryEnricher, | ||
expectedDisplayType: String | ||
): List[TypedMap] = { | ||
val st = connection.prepareStatement(query) | ||
val meta = st.getMetaData | ||
val state = DatabaseQueryEnricher.TransformationState( | ||
query = query, | ||
argsCount = 1, | ||
tableDef = TableDefinition(meta), | ||
strategy = ResultSetStrategy | ||
) | ||
st.close() | ||
val invoker = databaseQueryEnricher.implementation(Map.empty, dependencies = Nil, Some(state)) | ||
returnType(databaseQueryEnricher, state).display shouldBe expectedDisplayType | ||
val resultF = invoker.invokeService(parameters) | ||
Await.result(resultF, 5 seconds).asInstanceOf[java.util.List[TypedMap]].asScala.toList | ||
} | ||
|
||
def updateWithEnricher( | ||
query: String, | ||
connection: Connection, | ||
parameters: Map[String, AnyRef], | ||
databaseQueryEnricher: DatabaseQueryEnricher | ||
): Unit = { | ||
val st = connection.prepareStatement(query) | ||
st.close() | ||
val state = DatabaseQueryEnricher.TransformationState( | ||
query = query, | ||
argsCount = 1, | ||
tableDef = TableDefinition(Nil), | ||
strategy = UpdateResultStrategy | ||
) | ||
val invoker = databaseQueryEnricher.implementation(Map.empty, dependencies = Nil, Some(state)) | ||
returnType(databaseQueryEnricher, state).display shouldBe "Integer" | ||
val resultF = invoker.invokeService(parameters) | ||
Await.result(resultF, 5 seconds).asInstanceOf[Integer] | ||
} | ||
|
||
} |
Oops, something went wrong.