Skip to content

Commit

Permalink
Merge pull request #404 from ryankwagner/simplifyPipelineCall
Browse files Browse the repository at this point in the history
Simplify pipeline filter render with function call.
  • Loading branch information
pranavbhole authored Feb 22, 2019
2 parents b2301df + 101cba8 commit a0d51cc
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 59 deletions.
2 changes: 1 addition & 1 deletion api-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<artifactId>maha-parent</artifactId>
<groupId>com.yahoo.maha</groupId>
<version>5.241-SNAPSHOT</version>
<version>5.242-SNAPSHOT</version>
</parent>

<name>maha api-example</name>
Expand Down
2 changes: 1 addition & 1 deletion api-jersey/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>com.yahoo.maha</groupId>
<artifactId>maha-parent</artifactId>
<version>5.241-SNAPSHOT</version>
<version>5.242-SNAPSHOT</version>
</parent>

<name>maha api-jersey</name>
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.yahoo.maha</groupId>
<artifactId>maha-parent</artifactId>
<version>5.241-SNAPSHOT</version>
<version>5.242-SNAPSHOT</version>
</parent>

<name>maha core</name>
Expand Down
76 changes: 31 additions & 45 deletions core/src/main/scala/com/yahoo/maha/core/query/QueryGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,22 @@ object QueryGeneratorHelper {
}
}

def getFieldMapByColumn(name: String
, column: Column
, fact: Fact
, publicFact: PublicFact
, colFn: Column => String): Map[String, (String, String)] = {
val nameOrAlias: String = column.alias.getOrElse(column.name)
if(fact.dimColMap.contains(nameOrAlias))
Map.empty
else if (fact.factColMap.contains(nameOrAlias)) {
Map(name -> (nameOrAlias, colFn(column)))
} else {
throw new IllegalArgumentException(
s"Unknown fact column: publicFact=${publicFact.name}, fact=${fact.name} alias=${column.alias}, name=$nameOrAlias")
}
}

def handleFilterRender(filter: Filter,
publicFact: PublicFact,
fact: Fact,
Expand All @@ -273,54 +289,24 @@ object QueryGeneratorHelper {
val fieldNames: mutable.ArrayBuffer[String] = new ArrayBuffer[String]()
val isMultiField: Boolean = filter.isInstanceOf[MultiFieldForcedFilter]

fieldNames += publicFact.aliasToNameColumnMap(filter.field)
fieldNames += filter.field
if(isMultiField)
fieldNames += publicFact.aliasToNameColumnMap(filter.asInstanceOf[MultiFieldForcedFilter].compareTo)

val baseFieldName = fieldNames.remove(0)
if (fact.dimColMap.contains(baseFieldName)) {

FilterSql.renderFilter(
filter,
aliasToNameMapFull,
Map.empty,
fact.columnsByNameMap,
engine,
literalMapper
)

} else if (fact.factColMap.contains(baseFieldName)) {
val column = fact.columnsByNameMap(baseFieldName)
val exp = colFn(column)

if(!isMultiField) {
FilterSql.renderFilter(
filter,
queryContext.factBestCandidate.publicFact.aliasToNameColumnMap,
Map(filter.field -> (baseFieldName, exp)),
fact.columnsByNameMap,
engine,
literalMapper
)
} else {
val multiFieldForcedFilter = filter.asInstanceOf[MultiFieldForcedFilter]
val compareToFieldName = fieldNames.remove(0)
val compareToColumn = fact.columnsByNameMap(compareToFieldName)
val secondExp = colFn(compareToColumn)
FilterSql.renderFilter(
filter,
queryContext.factBestCandidate.publicFact.aliasToNameColumnMap,
Map(multiFieldForcedFilter.field -> (baseFieldName, exp), multiFieldForcedFilter.compareTo -> (compareToColumn.alias.getOrElse(compareToColumn.name), secondExp)),
fact.columnsByNameMap,
engine,
literalMapper
)
}
fieldNames += filter.asInstanceOf[MultiFieldForcedFilter].compareTo

} else {
throw new IllegalArgumentException(
s"Unknown fact column: publicFact=${publicFact.name}, fact=${fact.name} alias=${filter.field}, name=$baseFieldName")
var fMap = new mutable.HashMap[String, (String, String)]()

for (fieldName <- fieldNames) {
fMap ++= getFieldMapByColumn(fieldName, fact.columnsByNameMap(publicFact.aliasToNameColumnMap(fieldName)), fact, publicFact, colFn)
}

FilterSql.renderFilter(
filter,
aliasToNameMapFull,
fMap.toMap,
fact.columnsByNameMap,
engine,
literalMapper
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion db/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.yahoo.maha</groupId>
<artifactId>maha-parent</artifactId>
<version>5.241-SNAPSHOT</version>
<version>5.242-SNAPSHOT</version>
</parent>

<name>maha db</name>
Expand Down
2 changes: 1 addition & 1 deletion druid-lookups/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>maha-parent</artifactId>
<groupId>com.yahoo.maha</groupId>
<version>5.241-SNAPSHOT</version>
<version>5.242-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion druid/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>com.yahoo.maha</groupId>
<artifactId>maha-parent</artifactId>
<version>5.241-SNAPSHOT</version>
<version>5.242-SNAPSHOT</version>
</parent>

<name>maha druid executor</name>
Expand Down
2 changes: 1 addition & 1 deletion job-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.yahoo.maha</groupId>
<artifactId>maha-parent</artifactId>
<version>5.241-SNAPSHOT</version>
<version>5.242-SNAPSHOT</version>
</parent>

<name>maha job service</name>
Expand Down
2 changes: 1 addition & 1 deletion oracle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>com.yahoo.maha</groupId>
<artifactId>maha-parent</artifactId>
<version>5.241-SNAPSHOT</version>
<version>5.242-SNAPSHOT</version>
</parent>

<name>maha oracle executor</name>
Expand Down
2 changes: 1 addition & 1 deletion par-request-2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>com.yahoo.maha</groupId>
<artifactId>maha-parent</artifactId>
<version>5.241-SNAPSHOT</version>
<version>5.242-SNAPSHOT</version>
</parent>


Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.yahoo.maha</groupId>
<artifactId>maha-parent</artifactId>
<version>5.241-SNAPSHOT</version>
<version>5.242-SNAPSHOT</version>
<packaging>pom</packaging>

<name>maha parent</name>
Expand Down
2 changes: 1 addition & 1 deletion presto/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>com.yahoo.maha</groupId>
<artifactId>maha-parent</artifactId>
<version>5.241-SNAPSHOT</version>
<version>5.242-SNAPSHOT</version>
</parent>

<name>maha presto executor</name>
Expand Down
2 changes: 1 addition & 1 deletion request-log/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.yahoo.maha</groupId>
<artifactId>maha-parent</artifactId>
<version>5.241-SNAPSHOT</version>
<version>5.242-SNAPSHOT</version>
</parent>

<name>maha request log</name>
Expand Down
2 changes: 1 addition & 1 deletion service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>com.yahoo.maha</groupId>
<artifactId>maha-parent</artifactId>
<version>5.241-SNAPSHOT</version>
<version>5.242-SNAPSHOT</version>
</parent>

<name>maha service</name>
Expand Down
2 changes: 1 addition & 1 deletion worker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.yahoo.maha</groupId>
<artifactId>maha-parent</artifactId>
<version>5.241-SNAPSHOT</version>
<version>5.242-SNAPSHOT</version>
</parent>

<name>maha worker</name>
Expand Down

0 comments on commit a0d51cc

Please sign in to comment.