Skip to content

Instantly share code, notes, and snippets.

@ixixi
Last active August 29, 2015 14:03
Show Gist options
  • Save ixixi/c16f9d9af0d1b3d282c6 to your computer and use it in GitHub Desktop.
Save ixixi/c16f9d9af0d1b3d282c6 to your computer and use it in GitHub Desktop.
ScalaUDFExample
package in.ixixi.norikra.udf
import com.espertech.esper.epl.agg.aggregator.AggregationMethod
class ExampleScalaUDF extends AggregationMethod{
var counter = 0L
def getValueType: Class[_] = classOf[Long]
def enter(value: AnyRef) { counter += value.toString.length }
def leave(value: AnyRef) { counter -= value.toString.length }
def getValue: AnyRef = (counter:java.lang.Long):AnyRef
def clear { counter = 0L }
}
package in.ixixi.norikra.udf
import com.espertech.esper.client.hook.AggregationFunctionFactory
import com.espertech.esper.epl.agg.aggregator.AggregationMethod
import com.espertech.esper.epl.agg.service.AggregationValidationContext
class ExampleScalaUDFFactory extends AggregationFunctionFactory{
def setFunctionName(functionName: String)
def validate(validationContext: AggregationValidationContext)
def getValueType: Class[_] = classOf[Long]
def newAggregator: AggregationMethod = new ExampleScalaUDF
}
require 'java'
require 'norikra/udf'
module Norikra
module UDF
class ScalaUDFExample < Norikra::UDF::AggregationSingle
def self.init
require 'norikra-udf-scala-example.jar'
end
def definition
["strlength", "in.ixixi.norikra.udf.ExampleScalaUDFFactory"]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment