forked from finos/vuu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6660ca
commit 33a9c21
Showing
8 changed files
with
145 additions
and
43 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
47 changes: 47 additions & 0 deletions
47
...lugin/src/main/scala/org/finos/vuu/feature/ignite/filter/SqlFilterColumnValueParser.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,47 @@ | ||
package org.finos.vuu.feature.ignite.filter | ||
|
||
import com.typesafe.scalalogging.StrictLogging | ||
import org.finos.vuu.util.schema.typeConversion.TypeConverter.buildConverterName | ||
import org.finos.vuu.util.schema.{SchemaField, SchemaMapper} | ||
|
||
trait SqlFilterColumnValueParser { | ||
def parseColumnValue(columnName: String, columnValue: String): Option[(SchemaField, String)] | ||
def parseColumnValues(columnName: String, columnValues: List[String]): Option[(SchemaField, List[String])] | ||
} | ||
|
||
object SqlFilterColumnValueParser { | ||
def apply(schemaMapper: SchemaMapper): SqlFilterColumnValueParser = new ColumnValueParser(schemaMapper) | ||
} | ||
|
||
private class ColumnValueParser(private val mapper: SchemaMapper) extends SqlFilterColumnValueParser with StrictLogging { | ||
|
||
override def parseColumnValue(columnName: String, columnValue: String): Option[(SchemaField, String)] = { | ||
mapper.getMappedExternalField(columnName).flatMap(f => parseValue(f, columnName, columnValue).map((f, _))) | ||
} | ||
|
||
override def parseColumnValues(columnName: String, columnValues: List[String]): Option[(SchemaField, List[String])] = { | ||
mapper.getMappedExternalField(columnName) match { | ||
case Some(f) => Some(f, columnValues.flatMap(v => parseValue(f, columnName, v))) | ||
case None => None | ||
} | ||
} | ||
|
||
private def parseValue(field: SchemaField, columnName: String, columnValue: String): Option[String] = { | ||
def useDefaultToString = logErrorAndUseDefaultToString(field) | ||
|
||
mapper.parseStringToColumnType(columnValue, columnName) | ||
.flatMap(mapper.convertColumnValueToMappedExternalType(_, columnName)) | ||
.map(v => mapper.convertExternalValueToString(v, field.name).getOrElse(useDefaultToString(v))) | ||
} | ||
|
||
private def logErrorAndUseDefaultToString(field: SchemaField): Any => String = { | ||
extValue => | ||
logger.warn( | ||
s"Could not find a converter [${buildConverterName(field.dataType, classOf[String])}] " + | ||
s"required for SQL filters to be applied to ${field.name}. Falling back to using the " + | ||
s"default `toString`." | ||
) | ||
Option(extValue).map(_.toString).orNull | ||
} | ||
|
||
} |
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