-
Notifications
You must be signed in to change notification settings - Fork 156
RTS 795 #589
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
Merged
Merged
RTS 795 #589
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5308ce6
Add tests for Create Table and Describe queries
alexmoore 6070567
Cleanup and reuse some assertion code
alexmoore 283ad20
Add bad create table, fix assertions for common query code
alexmoore a96e334
Adding Fancy Describe command
alexmoore 711ed9b
Add missing equals() for ColumnDescription
alexmoore e28b351
Add missing equals() for FullColumnDescription
alexmoore f697e98
Add/Expand javadocs for TS DESCRIBE code.
alexmoore 1de5eb6
Address PR issues
alexmoore 2005036
Switch to interitance for FullColumnDescription
alexmoore File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/main/java/com/basho/riak/client/api/commands/timeseries/DescribeTable.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package com.basho.riak.client.api.commands.timeseries; | ||
|
|
||
| import com.basho.riak.client.api.RiakCommand; | ||
| import com.basho.riak.client.core.RiakCluster; | ||
| import com.basho.riak.client.core.RiakFuture; | ||
| import com.basho.riak.client.core.operations.ts.DescribeTableOperation; | ||
| import com.basho.riak.client.core.query.timeseries.TableDefinition; | ||
|
|
||
| /** | ||
| * Time Series DescribeTable Command | ||
| * Allows you to fetch a table definition from Riak Time Series. | ||
| * | ||
| * @author Alex Moore <amoore at basho dot com> | ||
| * @since 2.0.4 | ||
| */ | ||
| public class DescribeTable extends RiakCommand<TableDefinition, String> | ||
| { | ||
| private final String tableName; | ||
|
|
||
| /** | ||
| * Create a new DescribeTable command. | ||
| * No Builder is required. | ||
| * | ||
| * @param tableName The name of the table to fetch a definition for. Required, must not be empty or null. | ||
| */ | ||
| public DescribeTable(String tableName) | ||
| { | ||
| if(tableName == null || tableName.isEmpty()) | ||
| { | ||
| throw new IllegalArgumentException("Table Name must not be null or empty."); | ||
| } | ||
|
|
||
| this.tableName = tableName; | ||
| } | ||
|
|
||
| @Override | ||
| protected RiakFuture<TableDefinition, String> executeAsync(RiakCluster cluster) | ||
| { | ||
| RiakFuture<TableDefinition, String> future = | ||
| cluster.execute(buildCoreOperation()); | ||
|
|
||
| return future; | ||
| } | ||
|
|
||
| private DescribeTableOperation buildCoreOperation() | ||
| { | ||
| return new DescribeTableOperation(this.tableName); | ||
| } | ||
| } |
76 changes: 76 additions & 0 deletions
76
src/main/java/com/basho/riak/client/core/operations/ts/DescribeTableOperation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package com.basho.riak.client.core.operations.ts; | ||
|
|
||
| import com.basho.riak.client.core.operations.PBFutureOperation; | ||
| import com.basho.riak.client.core.query.timeseries.PbResultFactory; | ||
| import com.basho.riak.client.core.query.timeseries.TableDefinition; | ||
| import com.basho.riak.protobuf.RiakMessageCodes; | ||
| import com.basho.riak.protobuf.RiakTsPB; | ||
| import com.google.protobuf.ByteString; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * An operation to query a table definition from Riak Time Series. | ||
| * | ||
| * @author Alex Moore <amoore at basho dot com> | ||
| * @since 2.0.4 | ||
| */ | ||
| public class DescribeTableOperation extends PBFutureOperation<TableDefinition, RiakTsPB.TsQueryResp, String> | ||
| { | ||
| private final String tableName; | ||
| private final String queryText; | ||
|
|
||
| public DescribeTableOperation(String tableName) | ||
| { | ||
| this(new Builder(tableName)); | ||
| } | ||
|
|
||
| private DescribeTableOperation(Builder builder) | ||
| { | ||
| super(RiakMessageCodes.MSG_TsQueryReq, | ||
| RiakMessageCodes.MSG_TsQueryResp, | ||
| RiakTsPB.TsQueryReq.newBuilder().setQuery(builder.interpolationBuilder), | ||
| RiakTsPB.TsQueryResp.PARSER); | ||
|
|
||
| this.queryText = builder.queryText; | ||
| this.tableName = builder.tableName; | ||
| } | ||
|
|
||
| @Override | ||
| protected TableDefinition convert(List<RiakTsPB.TsQueryResp> responses) | ||
| { | ||
| // This is not a streaming op, there will only be one response | ||
| final RiakTsPB.TsQueryResp response = checkAndGetSingleResponse(responses); | ||
| return PbResultFactory.convertDescribeResp(this.tableName, response); | ||
| } | ||
|
|
||
| @Override | ||
| public String getQueryInfo() | ||
| { | ||
| return this.queryText; | ||
| } | ||
|
|
||
| public static class Builder | ||
| { | ||
| private final String tableName; | ||
| private final String queryText; | ||
| private final RiakTsPB.TsInterpolation.Builder interpolationBuilder = RiakTsPB.TsInterpolation.newBuilder(); | ||
|
|
||
| public Builder(String tableName) | ||
| { | ||
| if (tableName == null || tableName.length() == 0) | ||
| { | ||
| throw new IllegalArgumentException("Table Name cannot be null or empty"); | ||
| } | ||
|
|
||
| this.tableName = tableName; | ||
| this.queryText = String.format("DESCRIBE %s", tableName); | ||
| this.interpolationBuilder.setBase(ByteString.copyFromUtf8(queryText)); | ||
| } | ||
|
|
||
| public DescribeTableOperation build() | ||
| { | ||
| return new DescribeTableOperation(this); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
src/main/java/com/basho/riak/client/core/query/timeseries/FullColumnDescription.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| package com.basho.riak.client.core.query.timeseries; | ||
|
|
||
| /** | ||
| * Holds a complete definition for a Table Column in Time Series Riak. | ||
| * Immutable once created. | ||
| * | ||
| * @author Alex Moore <amoore at basho dot com> | ||
| * @since 2.0.4 | ||
| */ | ||
| public class FullColumnDescription extends ColumnDescription | ||
| { | ||
| private final boolean isNullable; | ||
| private final Integer partitionKeyOrdinal; | ||
| private final Integer localKeyOrdinal; | ||
|
|
||
| /** | ||
| * Creates a basic FullColumnDescription, for non-key columns. | ||
| * @param name The name of the column. Required - must not be null or an empty string. | ||
| * @param type The type of the column. Required - must not be null. | ||
| * @param isNullable The nullability of the column. | ||
| * @throws IllegalArgumentException if Column Name or Column Type are null or empty. | ||
| */ | ||
| public FullColumnDescription(String name, | ||
| ColumnDescription.ColumnType type, | ||
| boolean isNullable) | ||
| { | ||
| this(name, type, isNullable, null, null); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a FullColumnDescription. Useful for key columns where the partition and local key oridinals are the same. | ||
| * @param name The name of the column. Required - must not be null or an empty string. | ||
| * @param type The type of the column. Required - must not be null. | ||
| * @param isNullable The nullability of the column. | ||
| * @param keyOrdinal The ordinal number of where this column appears in the ordered Local Key column set. | ||
| * <b>Use null if not a key column.</b> | ||
| * @throws IllegalArgumentException if Column Name or Column Type are null or empty. | ||
| */ | ||
| public FullColumnDescription(String name, | ||
| ColumnDescription.ColumnType type, | ||
| boolean isNullable, | ||
| Integer keyOrdinal) | ||
| { | ||
| this(name, type, isNullable, keyOrdinal, keyOrdinal); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a FullColumnDescription. | ||
| * Useful for automating creation of FullColumnDescriptions where the values can vary. | ||
| * @param name The name of the column. Required - must not be null or an empty string. | ||
| * @param type The type of the column. Required - must not be null. | ||
| * @param isNullable The nullability of the column. | ||
| * @param partitionKeyOrdinal The ordinal number of where this column appears in | ||
| * the ordered Partition Key column set. | ||
| * <b>Use null if not a key column.</b> | ||
| * @param localKeyOrdinal The ordinal number of where this column appears in | ||
| * the ordered Local Key column set. | ||
| * <b>Use null if not a key column.</b> | ||
| * @throws IllegalArgumentException if Column Name or Column Type are null or empty. | ||
| */ | ||
| public FullColumnDescription(String name, | ||
| ColumnDescription.ColumnType type, | ||
| boolean isNullable, | ||
| Integer partitionKeyOrdinal, | ||
| Integer localKeyOrdinal) | ||
| { | ||
| super(name, type); | ||
| this.isNullable = isNullable; | ||
| this.partitionKeyOrdinal = partitionKeyOrdinal; | ||
| this.localKeyOrdinal = localKeyOrdinal; | ||
| } | ||
|
|
||
| /** | ||
| * Whether this column's values are nullable. | ||
| * @return boolean | ||
| */ | ||
| public boolean isNullable() | ||
| { | ||
| return isNullable; | ||
| } | ||
|
|
||
| /** | ||
| * Whether this column is a member of the Partition Key column set. | ||
| * @return boolean. | ||
| */ | ||
| public boolean isPartitionKeyMember() | ||
| { | ||
| return partitionKeyOrdinal != null; | ||
| } | ||
|
|
||
| /** | ||
| * Whether this column is a member of the Local Key column set. | ||
| * @return boolean. | ||
| */ | ||
| public boolean isLocalKeyMember() | ||
| { | ||
| return localKeyOrdinal != null; | ||
| } | ||
|
|
||
| /** | ||
| * Get the ordinal number of where this column appears in the ordered Partition Key column set. | ||
| * @return Integer if {@link #isPartitionKeyMember()} is <i>true</i>, | ||
| * <b>null</b> if {@link #isPartitionKeyMember()} is <i>false</i>. | ||
| */ | ||
| public Integer getPartitionKeyOrdinal() | ||
| { | ||
| return partitionKeyOrdinal; | ||
| } | ||
|
|
||
| /** | ||
| * Get the ordinal number of where this column appears in the ordered Local Key column set. | ||
| * @return Integer if {@link #isLocalKeyMember()} is <i>true</i>, | ||
| * <b>null</b> if {@link #isLocalKeyMember()} is <i>false</i>. | ||
| */ | ||
| public Integer getLocalKeyOrdinal() | ||
| { | ||
| return localKeyOrdinal; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to add kinda sanity check of the row, just in case.. Maybe check number of cells or something like this.. As well as add a comment describes expected format