use of io.crate.analyze.QueriedSelectRelation in project crate by crate.
the class SplitPointsTest method testSplitPointsCreationWithFunctionInAggregation.
@Test
public void testSplitPointsCreationWithFunctionInAggregation() throws Exception {
QueriedSelectRelation relation = e.analyze("select sum(coalesce(x, 0)) + 10 from t1");
SplitPoints splitPoints = SplitPointsBuilder.create(relation);
assertThat(splitPoints.toCollect(), contains(isFunction("coalesce")));
assertThat(splitPoints.aggregates(), contains(isFunction("sum")));
}
use of io.crate.analyze.QueriedSelectRelation in project crate by crate.
the class SplitPointsTest method testSplitPointsCreationSelectItemAggregationsAreAlwaysAdded.
@Test
public void testSplitPointsCreationSelectItemAggregationsAreAlwaysAdded() throws Exception {
QueriedSelectRelation relation = e.analyze("select" + " sum(coalesce(x, 0::integer)), " + " sum(coalesce(x, 0::integer)) + 10 " + "from t1");
SplitPoints splitPoints = SplitPointsBuilder.create(relation);
assertThat(splitPoints.toCollect(), contains(isFunction("coalesce")));
assertThat(splitPoints.aggregates(), contains(isFunction("sum")));
}
use of io.crate.analyze.QueriedSelectRelation in project crate by crate.
the class SplitPointsTest method testAggregationPlusTableFunctionUsingAggregation.
@Test
public void testAggregationPlusTableFunctionUsingAggregation() throws Exception {
QueriedSelectRelation relation = e.analyze("select max(x), generate_series(0, max(x)) from t1");
SplitPoints splitPoints = SplitPointsBuilder.create(relation);
assertThat(splitPoints.toCollect(), contains(isReference("x")));
assertThat(splitPoints.aggregates(), contains(isFunction("max")));
assertThat(splitPoints.tableFunctions(), contains(isFunction("generate_series")));
}
use of io.crate.analyze.QueriedSelectRelation in project crate by crate.
the class SplitPointsTest method testTableFunctionArgsAndStandaloneColumnsAreAddedToCollect.
@Test
public void testTableFunctionArgsAndStandaloneColumnsAreAddedToCollect() throws Exception {
QueriedSelectRelation relation = e.analyze("select unnest(xs), x from t2");
SplitPoints splitPoints = SplitPointsBuilder.create(relation);
assertThat(splitPoints.toCollect(), contains(isReference("xs"), isReference("x")));
assertThat(splitPoints.tableFunctions(), contains(isFunction("unnest")));
}
use of io.crate.analyze.QueriedSelectRelation in project crate by crate.
the class SQLPrinter method print.
public static String print(QueriedSelectRelation relation) {
StringBuilder sb = new StringBuilder();
sb.append("SELECT ");
sb.append(Lists2.joinOn(", ", relation.outputs(), x -> x.toString(Style.QUALIFIED)));
if (relation.where() != Literal.BOOLEAN_TRUE) {
sb.append(" WHERE ");
sb.append(relation.where().toString(Style.QUALIFIED));
}
if (!relation.groupBy().isEmpty()) {
sb.append(" GROUP BY ");
sb.append(Lists2.joinOn(", ", relation.groupBy(), x -> x.toString(Style.QUALIFIED)));
}
Symbol having = relation.having();
if (having != null) {
sb.append(" HAVING ");
sb.append(having.toString(Style.QUALIFIED));
}
OrderBy orderBy = relation.orderBy();
if (orderBy != null) {
sb.append(" ORDER BY ");
process(orderBy, sb);
}
Symbol limit = relation.limit();
if (limit != null) {
sb.append(" LIMIT ");
sb.append(print(limit));
}
Symbol offset = relation.offset();
if (offset != null) {
sb.append(" OFFSET ");
sb.append(print(offset));
}
return sb.toString();
}
Aggregations