use of com.hortonworks.streamline.streams.catalog.UDF in project streamline by hortonworks.
the class StreamCatalogService method removeUDF.
public UDF removeUDF(Long id) {
UDF udf = new UDF();
udf.setId(id);
return dao.remove(new StorableKey(UDF_NAMESPACE, udf.getPrimaryKey()));
}
use of com.hortonworks.streamline.streams.catalog.UDF in project streamline by hortonworks.
the class StreamCatalogService method getUDF.
public UDF getUDF(Long id) {
UDF udf = new UDF();
udf.setId(id);
return this.dao.get(new StorableKey(UDF_NAMESPACE, udf.getPrimaryKey()));
}
use of com.hortonworks.streamline.streams.catalog.UDF in project streamline by hortonworks.
the class RuleParserTest method testParseAgg.
@Test
public void testParseAgg() throws Exception {
final UDF stddevp = new UDF();
stddevp.setClassName("foo.class.name");
stddevp.setDescription("stddev p");
stddevp.setId(100L);
stddevp.setJarStoragePath("jarstoragepath");
stddevp.setName("stddevp");
stddevp.setType(Udf.Type.AGGREGATE);
new Expectations() {
{
mockCatalogService.listStreamInfos(withAny(new ArrayList<QueryParam>()));
result = mockTopologyStream;
mockCatalogService.listUDFs();
result = Collections.singleton(stddevp);
mockTopologyStream.getStreamId();
result = "teststream";
mockTopologyStream.getFields();
result = Arrays.asList(Schema.Field.of("temperature", Schema.Type.LONG), Schema.Field.of("humidity", Schema.Type.LONG));
}
};
TopologyRule topologyRule = new TopologyRule();
topologyRule.setId(1L);
topologyRule.setName("Test");
topologyRule.setDescription("test rule");
topologyRule.setTopologyId(1L);
topologyRule.setVersionId(1L);
topologyRule.setSql("select stddevp(temperature) from teststream");
RuleParser ruleParser = new RuleParser(mockCatalogService, topologyRule.getSql(), topologyRule.getTopologyId(), topologyRule.getVersionId());
ruleParser.parse();
LOG.info("Projection: [{}]", ruleParser.getProjection());
assertEquals(1, ruleParser.getStreams().size());
assertEquals(new Stream("teststream", Arrays.asList(Schema.Field.of("temperature", Schema.Type.LONG), Schema.Field.of("humidity", Schema.Type.LONG))), ruleParser.getStreams().get(0));
assertNull(ruleParser.getGroupBy());
assertNull(ruleParser.getHaving());
}
use of com.hortonworks.streamline.streams.catalog.UDF in project streamline by hortonworks.
the class RuleParserTest method testParseComplex1.
@Test
public void testParseComplex1() throws Exception {
final UDF myFunc = new UDF();
myFunc.setClassName("foo.class.name");
myFunc.setDescription("My function");
myFunc.setId(Math.abs(new Random().nextLong()));
myFunc.setJarStoragePath("/udfstorage/");
myFunc.setName("UPPER");
myFunc.setType(Udf.Type.FUNCTION);
new Expectations() {
{
mockCatalogService.listStreamInfos(withAny(new ArrayList<QueryParam>()));
result = mockTopologyStream;
mockCatalogService.listUDFs();
result = Collections.singleton(myFunc);
mockTopologyStream.getStreamId();
result = "teststream";
mockTopologyStream.getFields();
result = Arrays.asList(Schema.Field.of("temperature", Schema.Type.LONG), Schema.Field.of("humidity", Schema.Type.LONG), Schema.Field.of("city", Schema.Type.STRING));
}
};
TopologyRule topologyRule = new TopologyRule();
topologyRule.setId(1L);
topologyRule.setName("Test");
topologyRule.setDescription("test rule");
topologyRule.setTopologyId(1L);
topologyRule.setVersionId(1L);
topologyRule.setSql("select temperature, humidity, city from teststream where temperature + humidity > 100 OR UPPER(city) = 'SFO'");
RuleParser ruleParser = new RuleParser(mockCatalogService, topologyRule.getSql(), topologyRule.getTopologyId(), topologyRule.getVersionId());
ruleParser.parse();
LOG.info("Projection: [{}]", ruleParser.getProjection());
assertNotNull(ruleParser.getProjection());
assertNotNull(ruleParser.getCondition());
assertEquals(1, ruleParser.getStreams().size());
assertNull(ruleParser.getGroupBy());
assertNull(ruleParser.getHaving());
}
use of com.hortonworks.streamline.streams.catalog.UDF in project streamline by hortonworks.
the class RuleParserTest method testParseUDF1.
@Test
public void testParseUDF1() throws Exception {
final UDF myFunc = new UDF();
myFunc.setClassName("foo.class.name");
myFunc.setDescription("My function");
myFunc.setId(Math.abs(new Random().nextLong()));
myFunc.setJarStoragePath("/udfstorage/");
myFunc.setName("myFunc");
myFunc.setType(Udf.Type.FUNCTION);
new Expectations() {
{
mockCatalogService.listStreamInfos(withAny(new ArrayList<QueryParam>()));
result = mockTopologyStream;
mockCatalogService.listUDFs();
result = Collections.singleton(myFunc);
mockTopologyStream.getStreamId();
result = "teststream";
mockTopologyStream.getFields();
result = Arrays.asList(Schema.Field.of("temperature", Schema.Type.LONG), Schema.Field.of("humidity", Schema.Type.LONG));
}
};
TopologyRule topologyRule = new TopologyRule();
topologyRule.setId(1L);
topologyRule.setName("Test");
topologyRule.setDescription("test rule");
topologyRule.setTopologyId(1L);
topologyRule.setVersionId(1L);
topologyRule.setSql("select myFunc(temperature) from teststream");
RuleParser ruleParser = new RuleParser(mockCatalogService, topologyRule.getSql(), topologyRule.getTopologyId(), topologyRule.getVersionId());
ruleParser.parse();
LOG.info("Projection: [{}]", ruleParser.getProjection());
assertNotNull(ruleParser.getProjection());
assertEquals(1, ruleParser.getStreams().size());
assertEquals(new Stream("teststream", Arrays.asList(Schema.Field.of("temperature", Schema.Type.LONG), Schema.Field.of("humidity", Schema.Type.LONG))), ruleParser.getStreams().get(0));
assertNull(ruleParser.getGroupBy());
assertNull(ruleParser.getHaving());
}
Aggregations