-
Notifications
You must be signed in to change notification settings - Fork 889
fix: Clause implements Serializable to suport using from an Apache Beam pipline #1163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Apache Beam pipline
|
Thanks @srfrnk! This looks straightforward. I'll look at this tomorrow morning and also look at the rest of the query logger classes to see if anything else should be made serializable. |
|
Sorry, it looks like I misunderstood when I made my original comment. I did not realize at the time that nothing in For example |
|
Currently this prevents the Apache Beam CassandraIO from having a Where clause defined in the reader which makes every read injest the full table - a tremendous waste of resources! To handle that I has to remove the code using your QueryBuilder to support a string Where clause. @tolbertam is there anyway to handle that differently? |
|
Is it more important that If you wanted the capability of using the import com.datastax.driver.core.CodecRegistry;
import java.util.List;
public class StringClause extends Clause {
private final String rawClause;
public StringClause(String rawClause) {
this.rawClause = rawClause;
}
@Override
String name() {
// only used for routing purposes
return null;
}
@Override
Object firstValue() {
// only used for routing purposes
return null;
}
@Override
void appendTo(StringBuilder sb, List<Object> values, CodecRegistry codecRegistry) {
sb.append(rawClause);
}
@Override
boolean containsBindMarker() {
return false;
}
} private static String generateRangeQuery(
String keyspace,
String table,
String where, // <-- change type back to String
String partitionKey,
BigInteger rangeStart,
BigInteger rangeEnd)
{
Select.Where builder = QueryBuilder.select().from(keyspace,table).where();
if(where!=null) {
builder = builder.and(new StringClause(where)); // <-- use StringClause to wrap raw string
}
String token=String.format("token(%s)",partitionKey);
if(rangeStart!=null) {
builder = builder.and(QueryBuilder.gte(token, rangeStart));
}
if(rangeEnd!=null) {
builder = builder.and(QueryBuilder.lt(token, rangeEnd));
}
String query = builder.toString();
LOG.debug("Cassandra generated read query : {}", query);
return query;
}This would allow you to build your full query using This could be generally useful enough that we add to the driver, but implementing |
|
Small caveat: that only works if |
|
Yes this was my first idea but I ruled it out since implementing Clause requires visibility to internal types - which means it can't be done from Apache Beam code. |
|
@srfrnk based on your last comment, are you OK if we close this PR? Thanks! |
|
I will be doing the fixes in my own fork and use this anyway in my code from now on so you can close this if you want. |
|
Thanks! |
I'd like to create a BEAM PR for the following:
srfrnk/beam@583c77c
However it has will require this PR for the driver to first propagate.