use of io.siddhi.query.api.execution.query.selection.Selector in project siddhi by wso2.
the class IncrementalDataPurger method getOnDemandQuery.
private OnDemandQuery getOnDemandQuery(Table table, long timeFrom, long timeTo) {
List<OutputAttribute> outputAttributes = new ArrayList<>();
outputAttributes.add(new OutputAttribute(new Variable(AGG_START_TIMESTAMP_COL)));
Selector selector = Selector.selector().addSelectionList(outputAttributes).groupBy(Expression.variable(AGG_START_TIMESTAMP_COL)).orderBy(Expression.variable(AGG_START_TIMESTAMP_COL), OrderByAttribute.Order.DESC).limit(Expression.value(1));
InputStore inputStore;
if (timeTo != 0) {
inputStore = InputStore.store(table.getTableDefinition().getId()).on(Expression.and(Expression.compare(Expression.variable(AGG_START_TIMESTAMP_COL), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(timeFrom)), Expression.compare(Expression.variable(AGG_START_TIMESTAMP_COL), Compare.Operator.LESS_THAN_EQUAL, Expression.value(timeTo))));
} else {
inputStore = InputStore.store(table.getTableDefinition().getId()).on(Expression.compare(Expression.variable(AGG_START_TIMESTAMP_COL), Compare.Operator.LESS_THAN_EQUAL, Expression.value(timeFrom)));
}
return OnDemandQuery.query().from(inputStore).select(selector);
}
use of io.siddhi.query.api.execution.query.selection.Selector in project siddhi by wso2.
the class SiddhiQLBaseVisitorImpl method visitStore_query.
@Override
public Object visitStore_query(SiddhiQLParser.Store_queryContext ctx) {
OutputStream outputStream;
OnDemandQuery onDemandQuery = OnDemandQuery.query();
if (ctx.FROM() != null) {
onDemandQuery.setType(OnDemandQuery.OnDemandQueryType.FIND);
onDemandQuery.from((InputStore) visit(ctx.store_input()));
if (ctx.query_section() != null) {
onDemandQuery = onDemandQuery.select((Selector) visit(ctx.query_section()));
}
} else if (ctx.query_section() != null) {
onDemandQuery.select((Selector) visit(ctx.query_section()));
if (ctx.UPDATE() != null && ctx.OR() != null) {
onDemandQuery.setType(OnDemandQuery.OnDemandQueryType.UPDATE_OR_INSERT);
Source source = (Source) visit(ctx.target());
if (source.isInnerStream || source.isFaultStream) {
throw newSiddhiParserException(ctx, "UPDATE OR INTO INSERT can be only used with Tables!");
}
if (ctx.set_clause() != null) {
outputStream = new UpdateOrInsertStream(source.streamId, (UpdateSet) visit(ctx.set_clause()), (Expression) visit(ctx.expression()));
populateQueryContext(outputStream, ctx);
} else {
outputStream = new UpdateOrInsertStream(source.streamId, (Expression) visit(ctx.expression()));
populateQueryContext(outputStream, ctx);
}
onDemandQuery.outStream(outputStream);
} else if (ctx.INSERT() != null) {
onDemandQuery.setType(OnDemandQuery.OnDemandQueryType.INSERT);
Source source = (Source) visit(ctx.target());
if (source.isInnerStream || source.isFaultStream) {
throw newSiddhiParserException(ctx, "INSERT can be only used with Tables!");
}
outputStream = new InsertIntoStream(source.streamId);
populateQueryContext(outputStream, ctx);
onDemandQuery.outStream(outputStream);
} else if (ctx.store_query_output() != null) {
outputStream = (OutputStream) visit(ctx.store_query_output());
if (outputStream instanceof DeleteStream) {
onDemandQuery.setType(OnDemandQuery.OnDemandQueryType.DELETE);
} else if (outputStream instanceof UpdateStream) {
onDemandQuery.setType(OnDemandQuery.OnDemandQueryType.UPDATE);
}
onDemandQuery.outStream(outputStream);
}
} else if (ctx.store_query_output() != null) {
outputStream = (OutputStream) visit(ctx.store_query_output());
if (outputStream instanceof DeleteStream) {
onDemandQuery.setType(OnDemandQuery.OnDemandQueryType.DELETE);
} else if (outputStream instanceof UpdateStream) {
onDemandQuery.setType(OnDemandQuery.OnDemandQueryType.UPDATE);
}
onDemandQuery.outStream(outputStream);
}
populateQueryContext(onDemandQuery, ctx);
return onDemandQuery;
}
use of io.siddhi.query.api.execution.query.selection.Selector in project siddhi by wso2.
the class SimpleQueryTestCase method test6.
@Test
public void test6() {
Selector selector = new Selector();
selector.select("symbol", Expression.isNull(Expression.variable("symbol")));
selector.select("symbol1", Expression.not(Expression.variable("symbol")));
selector.select("symbol2", Expression.in(Expression.compare(Expression.variable("symbol"), Compare.Operator.EQUAL, Expression.variable("foo")), "aTable"));
Selector selector1 = new Selector();
selector1.select("symbol", Expression.isNull(Expression.variable("symbol")));
selector1.select("symbol1", Expression.not(Expression.variable("symbol")));
selector1.select("symbol2", Expression.in(Expression.compare(Expression.variable("symbol"), Compare.Operator.EQUAL, Expression.variable("foo")), "aTable"));
AssertJUnit.assertTrue(selector.equals(selector1));
AssertJUnit.assertEquals(selector.hashCode(), selector1.hashCode());
String selectorString = "Selector{selectionList=[OutputAttribute{rename='symbol', " + "expression=IsNull{streamId='null', streamIndex=null, isInnerStream=false, " + "isFaultStream=false, expression=Variable{id='null', isInnerStream=false, " + "streamIndex=null, functionId='null', functionIndex=null, attributeName='symbol'}}}, " + "OutputAttribute{rename='symbol1', expression=Not{expression=Variable{id='null', " + "isInnerStream=false, streamIndex=null, functionId='null', functionIndex=null, " + "attributeName='symbol'}}}, OutputAttribute{rename='symbol2', " + "expression=In{expression=Compare{rightExpression=Variable{id='null', " + "isInnerStream=false, streamIndex=null, functionId='null', functionIndex=null, " + "attributeName='foo'}, operator=EQUAL, leftExpression=Variable{id='null', " + "isInnerStream=false, streamIndex=null, functionId='null', functionIndex=null, " + "attributeName='symbol'}}, sourceId='aTable'}}], groupByList=[], havingExpression=null, " + "orderByList=[], limit=null, offset=null}";
AssertJUnit.assertEquals(selector.toString(), selectorString);
}
use of io.siddhi.query.api.execution.query.selection.Selector in project siddhi by wso2.
the class SimpleQueryTestCase method selectortest2.
@Test(expectedExceptions = DuplicateAttributeException.class)
public void selectortest2() {
Selector selector = new Selector();
List<OutputAttribute> list = new ArrayList<>();
list.add(new OutputAttribute(Expression.variable("symbol")));
selector.select("symbol", Expression.variable("symbol")).orderBy(Expression.variable("avgPrice"), OrderByAttribute.Order.DESC).limit(Expression.value(5)).offset(Expression.value(2)).addSelectionList(list);
}
Aggregations