Skip to content

Commit 3123ebc

Browse files
committed
to fix aggregate functions that should be scripted
1 parent 5b27725 commit 3123ebc

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

bridge/src/main/scala/app/softnetwork/elastic/sql/bridge/ElasticAggregation.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,14 @@ object ElasticAggregation {
159159
val script = Script(s"$context$scriptSrc").lang("painless")
160160
buildScript(aggName, script)
161161
} else {
162-
buildField(aggName, sourceField)
162+
aggType match {
163+
case th: WindowFunction if th.shouldBeScripted =>
164+
val context = PainlessContext()
165+
val scriptSrc = th.identifier.painless(Some(context))
166+
val script = Script(s"$context$scriptSrc").lang("painless")
167+
buildScript(aggName, script)
168+
case _ => buildField(aggName, sourceField)
169+
}
163170
}
164171
}
165172

es6/bridge/src/main/scala/app/softnetwork/elastic/sql/bridge/ElasticAggregation.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,14 @@ object ElasticAggregation {
159159
val script = Script(s"$context$scriptSrc").lang("painless")
160160
buildScript(aggName, script)
161161
} else {
162-
buildField(aggName, sourceField)
162+
aggType match {
163+
case th: WindowFunction if th.shouldBeScripted =>
164+
val context = PainlessContext()
165+
val scriptSrc = th.identifier.painless(Some(context))
166+
val script = Script(s"$context$scriptSrc").lang("painless")
167+
buildScript(aggName, script)
168+
case _ => buildField(aggName, sourceField)
169+
}
163170
}
164171
}
165172

sql/src/main/scala/app/softnetwork/elastic/sql/function/package.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ package object function {
3737

3838
trait FunctionWithIdentifier extends Function {
3939
def identifier: Identifier
40+
41+
override def shouldBeScripted: Boolean = identifier.shouldBeScripted
4042
}
4143

4244
trait FunctionWithValue[+T] extends Function with TokenValue {

0 commit comments

Comments
 (0)