Skip to content
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

Add documentation about QueryBuilder #1031

Merged
merged 4 commits into from
Aug 15, 2018
Merged

Conversation

alexott
Copy link

@alexott alexott commented Jun 14, 2018

No description provided.

@tolbertam tolbertam added this to the 3.6.0 milestone Jun 14, 2018
@tolbertam tolbertam self-requested a review June 14, 2018 14:01
Copy link
Contributor

@adutra adutra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very comprehensive guide, truly impressive work.
My remarks are all about style, but please keep in mind that I'm not a native English speaker either, so you might want to get this PR reviewed by someone whose native language is English.

@@ -1,5 +1,268 @@
## Built statements

*Coming soon... In the meantime, see the javadoc for [QueryBuilder].*
Built statements are generated via [QueryBuilder]'s Fluent API. Use of Fluent API allows
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: "Use of Fluent API allows for easier build of complex queries, as opposed to the use of hardcoded query strings."

Note: The provider builders perform very little validation of the built query. There is
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "The provided builders".

invalid queries.

Queries built with `QueryBuilder` are execute the same way as other queries - via
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "are executed"


Queries built with `QueryBuilder` are execute the same way as other queries - via
`execute` or `executeAsync`. When query is built with putting all data into it, then it
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: " When a query is built with inlined values, then it doesn't differ much from a statement specified as a string."

`execute` or `executeAsync`. When query is built with putting all data into it, then it
doesn't differ much from statement specified as string. But it's also possible to build
the query with bind markers inside it, and then convert it into [prepared statement](../prepared/).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "into a prepared statement".


Specification of conditions is similar to the other operations described above, including
conditional delete with `ifExists` & `onlyIf`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "conditional deletes".


If you're repeating the same operation very often, the more effective way will be to
create the [prepared statement](../prepared/) from the `BuiltStatement`. To do it, instead
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "...create a prepared statement"

If you're repeating the same operation very often, the more effective way will be to
create the [prepared statement](../prepared/) from the `BuiltStatement`. To do it, instead
of the real values, use the bind marker that is created either by calling of `bindMarker`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: "...use bind markers created either by calling bindMarker (which generates a positional placeholder), or by calling bindMarker("name") (which creates a named placeholder)."

### Setting additional options

As in the case of the usual statements, you can also set additional options for given
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: "As it is the case for regular statements, you can also set options on built statements such as the consistency level..."

(with `enableTracing`/`disableTracing`), retry policy (with `setRetryPolicy`), etc.

Note: the call to these functions changes the object type from `BuiltStatement` to the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "from BuiltStatementtoStatementorRegularStatement`"

Copy link
Contributor

@olim7t olim7t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome contribution, thanks!

See a few typos and style suggestions inline.

Also it would be nice to show the generated CQL query for each example, as we did in the driver 4 manual.

[QueryBuilder]: http://docs.datastax.com/en/drivers/java/3.5/com/datastax/driver/core/querybuilder/QueryBuilder.html
[TableMetadata]: http://docs.datastax.com/en/drivers/java/3.5/com/datastax/driver/core/TableMetadata.html
[SchemaBuilder]: https://docs.datastax.com/en/drivers/java/3.5/com/datastax/driver/core/schemabuilder/SchemaBuilder.html
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: consistently use https in all URLs.


Queries built with `QueryBuilder` are executed the same way as other queries--via
`execute` or `executeAsync`. When query is built with inlined values, then it doesn't
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"When a query is built"?


Generation of `BuiltStatement` is easy--start by calling of one of the
[QueryBuilder]'s methods of that represent the CQL's "verb": `select`, `update`, `delete`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superfluous "of"?
"methods that represent"

Note: The `QueryBuilder` doesn't provide support for the full set of CQL. For
DDL operations (`CREATE TABLE`, etc.) you can use the [SchemaBuilder]. To perform other
operations you still need to use [simple statements](../simple/).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any example of queries that are neither covered by QueryBuilder nor SchemaBuilder? We try to stay pretty up-to-date...

Copy link
Author

@alexott alexott Jul 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for example, there is no support for ALTER TYPE,CREATE MATERIALIZED VIEW, roles management, etc.

Besides selection of the specific columns, there is also a possibility of calling of
arbitrary CQL function by using the `fcall` (this is just example, don't do this on real
data):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say "calling arbitrary CQL functions by using the fcall method

### Inserting data

Insertion of data is straightforward--you specify the target table in call to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"a call"?

```

It also possible to specify additional metadata for inserted data, such as TTL (time to live) or
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"It is also possible"


It also possible to specify additional metadata for inserted data, such as TTL (time to live) or
timestamp. This is achieved by using the `using` function and providing the `Using`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could say "achieved with the using method" to avoid the repetition.

```

Besides the most often used `set` operation, there is a plenty of operations for work with
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"plenty of operations" / "lots of operations"

Similarly to insert statements, it's also possible to perform conditional updates by
calling either `ifExists` (to perform the update only if the entry exists), or by calling
`onlyIf` with a `Clause` object—in this case the row will be updated only if the clause
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: use -- like you did in other places

@alexott
Copy link
Author

alexott commented Jul 27, 2018

Thank you for comments @olim7t ! I've pushed fixes for them...

@tolbertam tolbertam merged commit ce29eea into apache:3.x Aug 15, 2018
@tolbertam
Copy link
Contributor

Merged, thanks @alexott!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants