Skip to content

Commit

Permalink
Feature/sub query (#1)
Browse files Browse the repository at this point in the history
* Change in the format

* Added interfaces for basic functionality

* Setting the selection core inside the selection query

* Query mechanism operate on core

* Core implementations do the job

* Simplified from clause

* Changed query creation

* Formatted latest changes

* Added subquery successfully

* Supporting sub queries

* Removed access to public constructors

* Formatting

* Removed generics where not needed

* Removed unecessary generics

* Removed unnecessary diamond expression

* Simplified construction of select query

* Changed select query

* Added simplified subquery creation

* Added simplified subquery creation

* Changed query builder

* Fixed formatting

* Moving to subquery

* More fun with diamonds

* Generified sub query functionality

* Added influxdb query builder

* Minor changes

* Added flexibility on the query building

* Generified subqueries

* Sub query simplification

* Added sub query

* Added sub query feature

* Added test for subquery

* Added query string

* Added support for slimit

* Added tz support

* Added timezone test

* Added regex on clause

* Added formatting

* Added subqueries
  • Loading branch information
gkatzioura authored Sep 13, 2018
1 parent 98542d6 commit 05f2a03
Show file tree
Hide file tree
Showing 27 changed files with 1,599 additions and 357 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/influxdb/querybuilder/Appender.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;
import java.util.regex.Pattern;
import org.influxdb.querybuilder.clauses.ConjunctionClause;
import org.influxdb.querybuilder.clauses.SelectRegexClause;

public final class Appender {

Expand Down Expand Up @@ -89,6 +90,9 @@ public static StringBuilder appendName(final Object name, final StringBuilder st
appendName((String) name, stringBuilder);
} else if (name instanceof Column) {
appendName(((Column) name).getName(), stringBuilder);
} else if (name instanceof SelectRegexClause) {
SelectRegexClause selectRegexClause = (SelectRegexClause) name;
selectRegexClause.appendTo(stringBuilder);
} else if (name instanceof Function) {
Function functionCall = (Function) name;
stringBuilder.append(functionCall.getName()).append('(');
Expand Down
26 changes: 12 additions & 14 deletions src/main/java/org/influxdb/querybuilder/BuiltQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.influxdb.querybuilder.clauses.RegexClause;
import org.influxdb.querybuilder.clauses.SimpleClause;

public abstract class BuiltQuery extends Query {
public abstract class BuiltQuery extends Query implements QueryStringBuilder {

public BuiltQuery(final String database) {
super(null, database);
Expand All @@ -25,17 +25,15 @@ public BuiltQuery(final String database, final boolean requiresPost) {
super(null, database, requiresPost);
}

abstract StringBuilder buildQueryString();

static StringBuilder addSemicolonIfNeeded(final StringBuilder stringBuilder) {
int length = moveToEndOfText(stringBuilder);
static StringBuilder addSemicolonIfMissing(final StringBuilder stringBuilder) {
int length = trimLast(stringBuilder);
if (length == 0 || stringBuilder.charAt(length - 1) != ';') {
stringBuilder.append(';');
}
return stringBuilder;
}

private static int moveToEndOfText(final StringBuilder stringBuilder) {
static int trimLast(final StringBuilder stringBuilder) {
int length = stringBuilder.length();
while (length > 0 && stringBuilder.charAt(length - 1) <= ' ') {
length -= 1;
Expand All @@ -49,7 +47,7 @@ private static int moveToEndOfText(final StringBuilder stringBuilder) {
@Override
public String getCommand() {
StringBuilder sb = buildQueryString();
addSemicolonIfNeeded(sb);
addSemicolonIfMissing(sb);
return sb.toString();
}

Expand All @@ -67,16 +65,16 @@ public static final class QueryBuilder {
private QueryBuilder() {
}

public static Select.Builder select(final String... columns) {
public static SelectionQueryImpl select(final String... columns) {
return select((Object[]) columns);
}

public static Select.Builder select(final Object... columns) {
return new Select.Builder(Arrays.asList(columns));
}

public static Selection select() {
return new Selection();
public static SelectionQueryImpl select(final Object... columns) {
WhereCoreImpl whereCore = new WhereCoreImpl();
SelectCoreImpl selectCore =
new SelectCoreImpl(null, Arrays.asList(columns), false, whereCore);
whereCore.setStatement(selectCore);
return new SelectionQueryImpl(new SelectionCoreImpl());
}

public static Clause eq(final String name, final Object value) {
Expand Down
54 changes: 50 additions & 4 deletions src/main/java/org/influxdb/querybuilder/BuiltQueryDecorator.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package org.influxdb.querybuilder;

public class BuiltQueryDecorator<T extends BuiltQuery> extends BuiltQuery {
import org.influxdb.querybuilder.clauses.Clause;

T query;
public abstract class BuiltQueryDecorator<T extends SelectQueryImpl> extends BuiltQuery
implements Select {

BuiltQueryDecorator(final T query) {
SelectQueryImpl query;

public BuiltQueryDecorator() {
super(null);
}

public void setQuery(final T query) {
this.query = query;
}

Expand All @@ -15,12 +21,52 @@ public String getCommand() {
}

@Override
StringBuilder buildQueryString() {
public StringBuilder buildQueryString() {
return query.buildQueryString();
}

@Override
public StringBuilder buildQueryString(final StringBuilder stringBuilder) {
return query.buildQueryString(stringBuilder);
}

@Override
public String getDatabase() {
return query.getDatabase();
}

@Override
public Where where() {
return query.where();
}

@Override
public Where where(final Clause clause) {
return query.where(clause);
}

@Override
public Where where(final String text) {
return query.where(text);
}

@Override
public SelectQueryImpl orderBy(final Ordering ordering) {
return query.orderBy(ordering);
}

@Override
public SelectQueryImpl groupBy(final Object... columns) {
return query.groupBy(columns);
}

@Override
public SelectQueryImpl limit(final int limit) {
return query.limit(limit);
}

@Override
public SelectQueryImpl limit(final int limit, final long offSet) {
return query.limit(limit, offSet);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.influxdb.querybuilder;

interface QueryStringBuilder {

StringBuilder buildQueryString(final StringBuilder stringBuilder);

StringBuilder buildQueryString();
}
Loading

0 comments on commit 05f2a03

Please sign in to comment.