Search in sources :

Example 6 with UDF

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()));
}
Also used : UDF(com.hortonworks.streamline.streams.catalog.UDF) StorableKey(com.hortonworks.registries.storage.StorableKey)

Example 7 with UDF

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()));
}
Also used : UDF(com.hortonworks.streamline.streams.catalog.UDF) StorableKey(com.hortonworks.registries.storage.StorableKey)

Example 8 with UDF

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());
}
Also used : Expectations(mockit.Expectations) UDF(com.hortonworks.streamline.streams.catalog.UDF) ArrayList(java.util.ArrayList) TopologyStream(com.hortonworks.streamline.streams.catalog.TopologyStream) Stream(com.hortonworks.streamline.streams.layout.component.Stream) TopologyRule(com.hortonworks.streamline.streams.catalog.TopologyRule) Test(org.junit.Test)

Example 9 with UDF

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());
}
Also used : Expectations(mockit.Expectations) Random(java.util.Random) UDF(com.hortonworks.streamline.streams.catalog.UDF) ArrayList(java.util.ArrayList) TopologyRule(com.hortonworks.streamline.streams.catalog.TopologyRule) Test(org.junit.Test)

Example 10 with UDF

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());
}
Also used : Expectations(mockit.Expectations) Random(java.util.Random) UDF(com.hortonworks.streamline.streams.catalog.UDF) ArrayList(java.util.ArrayList) TopologyStream(com.hortonworks.streamline.streams.catalog.TopologyStream) Stream(com.hortonworks.streamline.streams.layout.component.Stream) TopologyRule(com.hortonworks.streamline.streams.catalog.TopologyRule) Test(org.junit.Test)

Aggregations

UDF (com.hortonworks.streamline.streams.catalog.UDF)15 Test (org.junit.Test)6 Timed (com.codahale.metrics.annotation.Timed)5 Path (javax.ws.rs.Path)5 TopologyRule (com.hortonworks.streamline.streams.catalog.TopologyRule)3 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 Expectations (mockit.Expectations)3 StorableKey (com.hortonworks.registries.storage.StorableKey)2 UnsupportedMediaTypeException (com.hortonworks.streamline.common.exception.service.exception.request.UnsupportedMediaTypeException)2 TopologyStream (com.hortonworks.streamline.streams.catalog.TopologyStream)2 Stream (com.hortonworks.streamline.streams.layout.component.Stream)2 Random (java.util.Random)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 MediaType (javax.ws.rs.core.MediaType)2 QueryParam (com.hortonworks.registries.common.QueryParam)1 Rule (com.hortonworks.streamline.streams.layout.component.rule.Rule)1 Udf (com.hortonworks.streamline.streams.layout.component.rule.expression.Udf)1