-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Row has changed check, contains filter, column names sorting (#1333)
* #907 add hasRowChanged.* methods on In-Mem/Virtual tables * #884 add `contains` operator to filters - also adds unit-tests in IgniteSqlFilterClauseTest. - also adds `escapeSpecialChars` method to escape special characters with `LIKE` operator. - adds small follow-up improvements to IgniteSqlQuery, introduces a factory method apply(sqlTemplate: String, args: Any*) for cleaner and flexible usage. * #1308 sort column names by their indexes in sent table meta * #884 add suggested improvements from review --------- Co-authored-by: Malik, Junaid <junaid.malik@ubs.com>
- Loading branch information
1 parent
1d571a1
commit 3c2bc32
Showing
20 changed files
with
401 additions
and
104 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
2 changes: 1 addition & 1 deletion
2
plugin/ignite-plugin/src/test/scala/org/finos/vuu/feature/ignite/IgniteTestStore.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
145 changes: 145 additions & 0 deletions
145
...plugin/src/test/scala/org/finos/vuu/feature/ignite/filter/IgniteSqlFilterClauseTest.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,145 @@ | ||
package org.finos.vuu.feature.ignite.filter | ||
|
||
import org.finos.vuu.core.table.SimpleColumn | ||
import org.finos.vuu.feature.ignite.IgniteSqlQuery | ||
import org.finos.vuu.feature.ignite.filter.IgniteSqlFilterClauseTest.schemaMapperWithGivenFields | ||
import org.finos.vuu.util.schema.{ExternalEntitySchema, SchemaField, SchemaMapperBuilder} | ||
import org.scalatest.featurespec.AnyFeatureSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class IgniteSqlFilterClauseTest extends AnyFeatureSpec with Matchers { | ||
|
||
Feature(s"RegexIgniteSqlFilterClause[RegexOp.Starts]}") { | ||
val schemaMapper = schemaMapperWithGivenFields(("tag", classOf[String]), ("age", classOf[Int])) | ||
|
||
Scenario("should return correct query when simple value passed") { | ||
val clause = RegexIgniteSqlFilterClause(RegexOp.Starts)("tag", "To") | ||
|
||
val result = clause.toSql(schemaMapper) | ||
|
||
result shouldEqual IgniteSqlQuery("tag LIKE ? ESCAPE '\\'", List("To%")) | ||
} | ||
|
||
Scenario("should return correct query with escaped special chars when value with special chars passed") { | ||
val clause = RegexIgniteSqlFilterClause(RegexOp.Starts)("tag", "100%_off\\") | ||
|
||
val result = clause.toSql(schemaMapper) | ||
|
||
result shouldEqual IgniteSqlQuery("tag LIKE ? ESCAPE '\\'", List("100\\%\\_off\\\\%")) | ||
} | ||
|
||
Scenario("should return empty query when non-string column") { | ||
val clause = RegexIgniteSqlFilterClause(RegexOp.Starts)("age", "15") | ||
|
||
val result = clause.toSql(schemaMapper) | ||
|
||
result shouldEqual IgniteSqlQuery.empty | ||
} | ||
|
||
Scenario("should return empty query when no mapped field found") { | ||
val clause = RegexIgniteSqlFilterClause(RegexOp.Starts)("tagged", "To") | ||
|
||
val result = clause.toSql(schemaMapper) | ||
|
||
result shouldEqual IgniteSqlQuery.empty | ||
} | ||
|
||
Scenario("should return expected string representation") { | ||
RegexIgniteSqlFilterClause(RegexOp.Starts)("tag", "abc").toString shouldEqual "RegexIgniteSqlFilterClause[Starts](tag, abc)" | ||
} | ||
} | ||
|
||
Feature(s"RegexIgniteSqlFilterClause[RegexOp.Ends]}") { | ||
val schemaMapper = schemaMapperWithGivenFields(("tag", classOf[String]), ("age", classOf[Int])) | ||
|
||
Scenario("should return correct query when simple value passed") { | ||
val clause = RegexIgniteSqlFilterClause(RegexOp.Ends)("tag", "To") | ||
|
||
val result = clause.toSql(schemaMapper) | ||
|
||
result shouldEqual IgniteSqlQuery("tag LIKE ? ESCAPE '\\'", List("%To")) | ||
} | ||
|
||
Scenario("should return correct query with escaped special chars when value with special chars passed") { | ||
val clause = RegexIgniteSqlFilterClause(RegexOp.Ends)("tag", "100%_off\\") | ||
|
||
val result = clause.toSql(schemaMapper) | ||
|
||
result shouldEqual IgniteSqlQuery("tag LIKE ? ESCAPE '\\'", List("%100\\%\\_off\\\\")) | ||
} | ||
|
||
Scenario("should return empty query when non-string column") { | ||
val clause = RegexIgniteSqlFilterClause(RegexOp.Ends)("age", "15") | ||
|
||
val result = clause.toSql(schemaMapper) | ||
|
||
result shouldEqual IgniteSqlQuery.empty | ||
} | ||
|
||
Scenario("should return empty query when no mapped field found") { | ||
val clause = RegexIgniteSqlFilterClause(RegexOp.Ends)("tagged", "To") | ||
|
||
val result = clause.toSql(schemaMapper) | ||
|
||
result shouldEqual IgniteSqlQuery.empty | ||
} | ||
|
||
Scenario("should return expected string representation") { | ||
RegexIgniteSqlFilterClause(RegexOp.Ends)("tag", "abc").toString shouldEqual "RegexIgniteSqlFilterClause[Ends](tag, abc)" | ||
} | ||
} | ||
|
||
Feature(s"RegexIgniteSqlFilterClause[RegexOp.Contains]}") { | ||
val schemaMapper = schemaMapperWithGivenFields(("tag", classOf[String]), ("age", classOf[Int])) | ||
|
||
Scenario("should return correct query when simple value passed") { | ||
val clause = RegexIgniteSqlFilterClause(RegexOp.Contains)("tag", "gold") | ||
|
||
val result = clause.toSql(schemaMapper) | ||
|
||
result shouldEqual IgniteSqlQuery("tag LIKE ? ESCAPE '\\'", List("%gold%")) | ||
} | ||
|
||
Scenario("should return correct query with escaped special chars when value with special chars passed") { | ||
val clause = RegexIgniteSqlFilterClause(RegexOp.Contains)("tag", "\\100%_off\\") | ||
|
||
val result = clause.toSql(schemaMapper) | ||
|
||
result shouldEqual IgniteSqlQuery("tag LIKE ? ESCAPE '\\'", List("%\\\\100\\%\\_off\\\\%")) | ||
} | ||
|
||
Scenario("should return empty query when non-string column") { | ||
val clause = RegexIgniteSqlFilterClause(RegexOp.Contains)("age", "15") | ||
|
||
val result = clause.toSql(schemaMapper) | ||
|
||
result shouldEqual IgniteSqlQuery.empty | ||
} | ||
|
||
Scenario("should return empty query when no mapped field found") { | ||
val clause = RegexIgniteSqlFilterClause(RegexOp.Contains)("tagged", "To") | ||
|
||
val result = clause.toSql(schemaMapper) | ||
|
||
result shouldEqual IgniteSqlQuery.empty | ||
} | ||
|
||
Scenario("should return expected string representation") { | ||
RegexIgniteSqlFilterClause(RegexOp.Contains)("tag", "abc").toString shouldEqual "RegexIgniteSqlFilterClause[Contains](tag, abc)" | ||
} | ||
} | ||
} | ||
|
||
private object IgniteSqlFilterClauseTest { | ||
private def schemaMapperWithGivenFields(fields: (String, Class[_])*) = { | ||
val fieldsAndColumns = fields.toList.zipWithIndex.map({case ((name, dataType), idx) => | ||
(SchemaField(name, dataType, idx), SimpleColumn(name, idx, dataType)) | ||
}) | ||
|
||
SchemaMapperBuilder(externalSchema(fieldsAndColumns.map(_._1)), fieldsAndColumns.map(_._2).toArray).build() | ||
} | ||
|
||
private def externalSchema(fields: List[SchemaField]) = TestSchema(fields) | ||
|
||
private case class TestSchema(override val fields: List[SchemaField]) extends ExternalEntitySchema | ||
} |
Oops, something went wrong.