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

#1318 functional test for usages of Schema mapper #1379

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a1344c0
#1318 example of how to use schema mapper to get data and update in m…
naleeha Apr 30, 2024
9ea52fb
#1318 helper function for scala and java collection converter
naleeha Apr 30, 2024
5d63f20
#1318 notes on next things to try
naleeha May 3, 2024
d9c930a
#1318 java example of using schema mapper
naleeha May 13, 2024
a9df733
#1318 fleshing out java schema mapper example
naleeha May 13, 2024
d6aedcc
#1318 fleshing out scala schema mapper example
naleeha May 13, 2024
2df15a4
#1318 refactoring scala example into test
naleeha May 13, 2024
e94cf76
#1318 added more scenario for schema mapper testing
naleeha May 14, 2024
0c5f04c
#1318 refactor schema mapper functional test to introduce base class
naleeha May 16, 2024
2d1f595
#1318 using data source for the functional test more generic so it is…
naleeha May 16, 2024
e58bc53
#1318 introduce function to create table columns from external schema
naleeha May 16, 2024
8b15000
#1318 adding virtualized table plugin table dependency in ignite plug…
naleeha May 16, 2024
18062b5
#1318 adding additional type for column builder
naleeha May 17, 2024
f099eb7
#1318 adding additional test scenario to be implemented
naleeha May 17, 2024
85236d3
#1318 adding java usecase tests for schema mapper
naleeha May 17, 2024
dbdd6ab
#1318 test cleanup
naleeha May 30, 2024
a47ab18
#1318 SchemaMapper functional test for virtualised table
naleeha May 30, 2024
0636990
#1318 clean up based on review comments
naleeha May 31, 2024
587b046
#1318 schema mapper functional test for when table column type is dif…
naleeha Jun 4, 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
6 changes: 6 additions & 0 deletions plugin/ignite-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
<version>0.9.65-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.finos.vuu.plugin</groupId>
<artifactId>virtualized-table-plugin</artifactId>
<version>0.9.65-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.finos.vuu.feature.ignite

import org.finos.vuu.core.sort.SortDirection
import org.finos.vuu.core.table.{ColumnValueProvider, Columns}
import org.finos.vuu.net.FilterSpec
import org.finos.vuu.plugin.virtualized.api.VirtualizedSessionTableDef
import org.finos.vuu.provider.VirtualizedProvider
import org.finos.vuu.test.{FakeDataSource, FakeInMemoryTable}
import org.finos.vuu.util.schema.{ExternalEntitySchema, SchemaMapperBuilder, SchemaMapperFunctionalTestBase, SchemaTestData}
import org.finos.vuu.viewport.ViewPort

class SchemaMapperFunctionalTest extends SchemaMapperFunctionalTestBase {

Feature("Filter data in virtualised table using schema mapper") {
Scenario("When table columns and entity fields has same type") {

val externalEntitySchema: ExternalEntitySchema = createExternalEntitySchema
val tableDef = VirtualizedSessionTableDef(
name = "MyExampleVirtualTable",
keyField = "id",
columns = Columns.fromExternalSchema(externalEntitySchema)
)
val schemaMapper = SchemaMapperBuilder(externalEntitySchema, tableDef.columns)
.build()
val table = new FakeInMemoryTable("SchemaMapTest", tableDef)

//simulate using typeahead
givenColumnQueryReturns("unique", "clientId", Array("5","6"))

val dataProvider = new TestVirtualProvider(fakeDataSource)
val columnValueProvider = dataProvider.asInstanceOf[ColumnValueProvider]
columnValueProvider.getUniqueValues("clientId")

//todo assert on the result returned for typeahead

//simulate using user entered filter and sort to the data query
val filterSpec = FilterSpec("orderId > 1 and ric starts \"ABC\"")
val sortSpec = Map("price" -> SortDirection.Ascending)

val filterAndSortSpecToSql = FilterAndSortSpecToSql(schemaMapper)
filterAndSortSpecToSql.sortToSql(sortSpec)
filterAndSortSpecToSql.filterToSql(filterSpec)

//todo assert that correct sql query is created - should use real ignite or assert on expected sql query?

//todo test once query is returned it can be mapped appropriate to table rows & assert on what exist in table
givenQueryReturns("filtered", List(
List("testId1", 5, 10.5),
List("testId2", 6, 11.5),
List("testId3", 5, 12.5),
))
fakeDataSource.getAsListOfValues("filtered")
}

Scenario("When table columns and entity fields has different type"){}
}
}


class TestVirtualProvider(fakeDataSource:FakeDataSource[SchemaTestData]) extends VirtualizedProvider {
override def runOnce(viewPort: ViewPort): Unit = ???

override def getUniqueValues(columnName: String): Array[String] = getColumnQueryResult("unique", columnName)

override def getUniqueValuesStartingWith(columnName: String, starts: String): Array[String] = ???

override def subscribe(key: String): Unit = ???

override def doStart(): Unit = ???

override def doStop(): Unit = ???

override def doInitialize(): Unit = ???

override def doDestroy(): Unit = ???

override val lifecycleId: String = "SchemaMapperFunctionalTest"

private def getColumnQueryResult(queryName: String, columnName:String): Array[String] = {
fakeDataSource.getColumnValues(queryName, columnName)
.getOrElse(throw new Exception("query does not exist in store. make sure it is setup"))
}
}
30 changes: 30 additions & 0 deletions vuu/src/main/java/org/finos/vuu/util/ScalaCollectionConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.finos.vuu.util;

import scala.jdk.CollectionConverters;

import java.util.List;
import java.util.Map;

public class ScalaCollectionConverter {

public static <K, V> scala.collection.immutable.Map<K, V> toScala(Map<K, V> m) {
return scala.collection.immutable.Map.from(scala.jdk.CollectionConverters.MapHasAsScala(m).asScala());
}

public static <T> scala.collection.Iterable<T> toScala(Iterable<T> l) {
return CollectionConverters.IterableHasAsScala(l).asScala();
}

public static <T> scala.collection.immutable.List<T> toScala(List<T> l) {
return CollectionConverters.IterableHasAsScala(l).asScala().toList();
}

public static <T> scala.collection.immutable.Seq<T> toScalaSeq(List<T> l) {
return CollectionConverters.IterableHasAsScala(l).asScala().toSeq();
}

public static <T> List<T> toJava(scala.collection.immutable.List<T> l) {
return CollectionConverters.SeqHasAsJava(l).asJava();
}
}

44 changes: 44 additions & 0 deletions vuu/src/main/scala/org/finos/vuu/api/ColumnBuilder.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.finos.vuu.api

import org.finos.vuu.core.table.{Column, Columns}

import scala.collection.mutable

class ColumnBuilder {

val columns = new mutable.ArrayBuilder.ofRef[String]()

def addString(columnName: String): ColumnBuilder = {
columns += (columnName + ":String")
this
}

def addDouble(columnName: String): ColumnBuilder = {
columns += (columnName + ":Double")
this
}

def addInt(columnName: String): ColumnBuilder = {
columns += (columnName + ":Int")
this
}

def addLong(columnName: String): ColumnBuilder = {
columns += (columnName + ":Long")
this
}

def addBoolean(columnName: String): ColumnBuilder = {
columns += (columnName + ":Boolean")
this
}

def addChar(columnName: String): ColumnBuilder = {
columns += (columnName + ":Char")
this
}

def build(): Array[Column] = Columns.fromNames(columns.result())
}


11 changes: 9 additions & 2 deletions vuu/src/main/scala/org/finos/vuu/core/table/Column.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.finos.vuu.core.table
import com.typesafe.scalalogging.StrictLogging
import org.finos.vuu.api.TableDef
import org.finos.vuu.core.table.column.CalculatedColumnClause
import org.finos.vuu.util.schema.ExternalEntitySchema
import org.finos.vuu.util.types.{DefaultTypeConverters, TypeConverterContainerBuilder}

import scala.util.Try
Expand Down Expand Up @@ -86,15 +87,21 @@ object Columns {
table.columns.filter(c => aliased.contains(c.name)) map (c => new AliasedJoinColumn(aliased(c.name), c.index, c.dataType, table, c).asInstanceOf[Column])
}

//def calculated(name: String, definition: String): Array[Column] = ???

def allFromExcept(table: TableDef, excludeColumns: String*): Array[Column] = {

val excluded = excludeColumns.map(s => s -> 1).toMap

table.columns.filterNot(c => excluded.contains(c.name)).map(c => new JoinColumn(c.name, c.index, c.dataType, table, c))
}

/**
* Create columns that use same name, type, order as the external entity fields
* */
def fromExternalSchema(externalSchema: ExternalEntitySchema): Array[Column] = {
externalSchema.fields.map(field => SimpleColumn(field.name, field.index, field.dataType))
.toArray
}

}

trait Column {
Expand Down
11 changes: 11 additions & 0 deletions vuu/src/test/java/org/finos/vuu/util/ScalaList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.finos.vuu.util;

import java.util.Arrays;

import static org.finos.vuu.util.ScalaCollectionConverter.toScala;

public class ScalaList {
public static <T> scala.collection.immutable.List<T> of(T... args) {
return toScala(Arrays.asList(args));
}
}
7 changes: 7 additions & 0 deletions vuu/src/test/java/org/finos/vuu/util/SchemaJavaTestData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.finos.vuu.util;

public class SchemaJavaTestData {
public String Id;
public int ClientId;
public double NotionalValue;
}
Loading
Loading