/** * Creates a {@code count(x)} built-in function call. * * @return the function call. */ public static Object count(Object column) { // consider a String literal as a column name for user convenience, // as CQL literals are not allowed here. if (column instanceof String) column = column(((String) column)); return new Utils.FCall("count", column); }
/** * Creates a {@code max(x)} built-in function call. * * @return the function call. */ public static Object max(Object column) { // consider a String literal as a column name for user convenience, // as CQL literals are not allowed here. if (column instanceof String) column = column(((String) column)); return new Utils.FCall("max", column); }
/** * Creates a {@code min(x)} built-in function call. * * @return the function call. */ public static Object min(Object column) { // consider a String literal as a column name for user convenience, // as CQL literals are not allowed here. if (column instanceof String) column = column(((String) column)); return new Utils.FCall("min", column); }
/** * Creates a {@code sum(x)} built-in function call. * * @return the function call. */ public static Object sum(Object column) { // consider a String literal as a column name for user convenience, // as CQL literals are not allowed here. if (column instanceof String) column = column(((String) column)); return new Utils.FCall("sum", column); }
/** * Creates an {@code avg(x)} built-in function call. * * @return the function call. */ public static Object avg(Object column) { // consider a String literal as a column name for user convenience, // as CQL literals are not allowed here. if (column instanceof String) column = column(((String) column)); return new Utils.FCall("avg", column); } }
/** * Creates a {@code toJson()} function call. This is a shortcut for {@code fcall("toJson", * QueryBuilder.column(name))}. * * <p>Support for JSON functions has been added in Cassandra 2.2. The {@code toJson()} function is * similar to {@code SELECT JSON} statements, but applies to a single column value instead of the * entire row, and produces a JSON-encoded string representing the normal Cassandra column value. * * <p>It may only be used in the selection clause of a {@code SELECT} statement. * * @param column the column to retrieve JSON from. * @return the function call. * @see <a href="http://cassandra.apache.org/doc/cql3/CQL-2.2.html#json">JSON Support for CQL</a> * @see <a href="http://www.datastax.com/dev/blog/whats-new-in-cassandra-2-2-json-support">JSON * Support in Cassandra 2.2</a> */ public static Object toJson(Object column) { // consider a String literal as a column name for user convenience, // as CQL literals are not allowed here. if (column instanceof String) column = column(((String) column)); return new Utils.FCall("toJson", column); }
assertThat(select().all().from("foo").groupBy("c1", column("c2"), raw("c3")).toString()) .isEqualTo("SELECT * FROM foo GROUP BY c1,c2,c3;"); assertThat( .all() .from("foo") .groupBy("c1", column("c2"), raw("c3")) .orderBy(asc("c1")) .toString()) .from("foo") .where(eq("x", 42)) .groupBy("c1", column("c2"), raw("c3")) .toString()) .isEqualTo("SELECT * FROM foo WHERE x=42 GROUP BY c1,c2,c3;"); .from("foo") .where(eq("x", 42)) .groupBy("c1", column("c2"), raw("c3")) .orderBy(asc("c1")) .toString())
select = select().fcall("* FROM bar; --", column("b")).from("foo"); assertEquals(select.toString(), query);
.execute( select() .fcall("avg", cast(column("i"), DataType.cfloat())) .as("iavg") .from(TABLE2)
/** * Generate a SELECT ... <strong>writetime(QueryBuilder.column("value")) AS write_time_2</strong> ... */ public final EntityWithComplexTypes_Select.ColsTM writeTimeWithCodec() { selection.fcall("writetime",QueryBuilder.column("value")).as("write_time_2"); return this; }
select = select().fcall("intToBlob", column("b")).from("foo"); assertEquals(select.toString(), query); select = select() .cast(fcall("writetime", column("country")), DataType.text()) .from("artists") .limit(2); select = select().fcall("avg", cast(column("v"), DataType.cfloat())).from("e"); assertEquals(select.toString(), query);
/** * Generate a SELECT ... <strong>writetime(QueryBuilder.column("value")) AS write_time_2</strong> ... */ public final EntityWithComplexTypes_Select.Cols writeTimeWithCodec() { selection.fcall("writetime",QueryBuilder.column("value")).as("write_time_2"); return this; }
/** * Generate a SELECT ... <strong>writetime(QueryBuilder.column("value")) AS write_time</strong> ... */ public final EntityWithComplexTypes_Select.ColsTM writeTime() { selection.fcall("writetime",QueryBuilder.column("value")).as("write_time"); return this; }
/** * Generate a SELECT ... <strong>writetime(QueryBuilder.column("value")) AS write_time</strong> ... */ public final EntityWithComplexTypes_Select.Cols writeTime() { selection.fcall("writetime",QueryBuilder.column("value")).as("write_time"); return this; }
/** * Generate a SELECT ... <strong>writetime(QueryBuilder.column("value")) AS write_time_2</strong> ... */ public final EntityWithComplexTypes_Select.Cols writeTimeWithCodec() { select.fcall("writetime",QueryBuilder.column("value")).as("write_time_2"); return new EntityWithComplexTypes_Select.Cols(select); }
private static SelectionOrAlias getSelection(Selection selection, Selector selector) { if (selector instanceof FunctionCall) { Object[] objects = ((FunctionCall) selector).getParameters().stream().map(param -> { if (param instanceof ColumnSelector) { return QueryBuilder.column(((ColumnSelector) param).getExpression()); } return param; }).toArray(); return selection.fcall(selector.getExpression(), objects); } return selection.column(selector.getExpression()); }
/** * Generate a SELECT ... <strong>writetime(QueryBuilder.column("value")) AS write_time</strong> ... */ public final EntityWithComplexTypes_Select.Cols writeTime() { select.fcall("writetime",QueryBuilder.column("value")).as("write_time"); return new EntityWithComplexTypes_Select.Cols(select); }
/** * Call "token" function with given parameters */ @SuppressWarnings("rawtypes") public static final <T extends AbstractCQLCompatibleType & FunctionCall> Long_Type token(final T input) { final List<Object> params = new ArrayList<>(); Validator.validateFalse(input.isFunctionCall(), "Invalid argument for 'token' function, it does not accept function call as argument, only simple column"); Validator.validateFalse(input.hasLiteralValue(), "Invalid argument for 'token' function, it does not accept literal value as argument, only simple column"); params.add(QueryBuilder.column((String)input.getValue())); return new Long_Type(Optional.empty()) { @Override public boolean isFunctionCall() { return true; } @Override public String functionName() { return "token"; } @Override public List<Object> parameters() { return params; } }; }
/** * Call "writetime" function with given parameters */ @SuppressWarnings("rawtypes") public static final <T extends AbstractCQLCompatibleType & FunctionCall> Long_Type writetime(final T input) { final List<Object> params = new ArrayList<>(); Validator.validateFalse(input.isFunctionCall(), "Invalid argument for 'writetime' function, it does not accept function call as argument, only simple column"); Validator.validateFalse(input.hasLiteralValue(), "Invalid argument for 'writetime' function, it does not accept literal value as argument, only simple column"); params.add(QueryBuilder.column((String)input.getValue())); return new Long_Type(Optional.empty()) { @Override public boolean isFunctionCall() { return true; } @Override public String functionName() { return "writetime"; } @Override public List<Object> parameters() { return params; } }; }
/** * Call "toJson" function with given parameters */ @SuppressWarnings("rawtypes") public static final <T extends AbstractCQLCompatibleType & FunctionCall> String_Type toJson(final T input) { final List<Object> params = new ArrayList<>(); Validator.validateFalse(input.isFunctionCall(), "Invalid argument for 'toJson' function, it does not accept function call as argument, only simple column"); Validator.validateFalse(input.hasLiteralValue(), "Invalid argument for 'toJson' function, it does not accept literal value as argument, only simple column"); params.add(QueryBuilder.column((String)input.getValue())); return new String_Type(Optional.empty()) { @Override public boolean isFunctionCall() { return true; } @Override public String functionName() { return "toJson"; } @Override public List<Object> parameters() { return params; } }; }