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

DOC: Add examples to the SQL docs #31633

Merged
merged 6 commits into from
Jul 3, 2018
Merged

Conversation

costin
Copy link
Member

@costin costin commented Jun 27, 2018

Wip on the documentation examples.
Put the tests into a separate suite to help with clarity and isolation.
The existing tests have different CVS tests (that include data type among other things) which are not relevant for the docs.
Also moved the library dataset into the test suite.
Additionally, used the same output from CLI in the JDBC test suite (a different PR should eliminate the JdbcTestUtils output entirely and only use the CliFormatter).

Once the infrastructure is in place, adding the examples goes quite smooth. I also like the SQL with table approach since it's easier to read (and applicable for all consumers - REST, JDBC, CLI).

@costin costin added >docs General docs changes v7.0.0 :Analytics/SQL SQL querying v6.4.0 labels Jun 27, 2018
@costin costin self-assigned this Jun 27, 2018
@costin costin requested review from nik9000 and astefan June 27, 2018 21:08
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

I'm fine with new CSV files and a new data set. Could we get away without DocsCsvSpecTestCase/JdbcDocCsvSpectIT if we do it during the regular CSV tests. If we're worried about time we could use `-Dtests.method='docs'?

makeAlias(client, "test_alias", "test_emp", "test_emp_copy");
makeAlias(client, "test_alias_emp", "test_emp", "test_emp_copy");
}

protected static void loadDocsDatasetIntoEs(RestClient client) throws Exception {
loadEmpDatasetIntoEs(client, "emp");
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to rename the one in tests to emp and load the library one for all the tests.

@costin
Copy link
Member Author

costin commented Jun 27, 2018

I ended up with a different test since for tests we have a number of indices that show up in SHOW TABLES or any type of FROM emp* query.
We have test_emp, test_emp_copy plus an alias to them.
If library and emp are placed in the same suite, the tests for SHOW TABLES need to be changed both in the docs and in the tests.
So in the interest of time, having this namespace between the test suite (that might get geo in the future, maybe the flight data) and the docs seems reasonable and not too much effort.
It can be definitely be revisited in the future but as of right now, I could come up with a single test suite and isolation between the datasets so they don't leak into each others commands.

Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

Fine by me. I'd prefer to figure out a way around it, but that can come later. I left one important thing and one minor structural thing.

// uncomment this to printout the result set and create new CSV tests
//
JdbcTestUtils.logLikeCLI(elastic, log);
//JdbcAssert.assertResultSets(expected, elastic, log);
Copy link
Member

Choose a reason for hiding this comment

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

This look like it isn't asserting anything. I don't mind the printing being enabled all the time but I think we should have the assert on, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right - the comment will disappear in the final commit. I'm printing stuff out to help with the docs (logging while asserting adds the log header which makes it harder to copy-paste the text output).

* That's not to say the two cannot be merged however that felt like too much of an effort
* at this stage and, to not keep things stalling, started with this approach.
*/
public abstract class DocsCsvSpecTestCase extends SpecBaseIntegrationTestCase {
Copy link
Member

Choose a reason for hiding this comment

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

Could you flatten this into into the JDBC spec test case so we don't have an abstract class with a single non-abstract child?

Copy link
Member Author

Choose a reason for hiding this comment

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

Roger that.

Significantly improve the example snippets in the documentation.
The examples are part of the test suite and checked nightly.
To help readability, the existing dataset was extended (test_emp renamed
to emp plus library).
Add examples to all sections
Fix two minor bugs in the JDBC driver discovered
Improve output of JDBC tests to be consistent with the CLI
Add lenient flag to JDBC asserts to allow type widening (a long is
equivalent to a integer as long as the value is the same)
@costin
Copy link
Member Author

costin commented Jul 2, 2018

Pushed the changes (including a rebase from master which looks like it didn't delete the existing comments probably because the commit itself was kept in place).

I've improved the tests and added example through-out the rest of the docs.
I've done a couple of improvements to the Jdbc tests mainly aligning its output with that of the CLI so one gets the same output regardless.
This lead to discovering two bugs in the driver (see #31734) so I picked up their changes (as they are small) since otherwise checking the CSV spec failed.

Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

I left a few questions. I still think the approach is good but have some questions about smaller parts of it.

// TESTRESPONSE[_cat]
["source","sql",subs="attributes,callouts,macros"]
----
include-tagged::{sql-specs}/docs.csv-spec[orderByScore]
Copy link
Member

Choose a reason for hiding this comment

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

👍

@@ -10,6 +10,8 @@ dependencies {

// JDBC testing dependencies
compile project(path: xpackModule('sql:jdbc'), configuration: 'nodeps')
compile project(path: xpackModule('sql:sql-proto'))
Copy link
Member

Choose a reason for hiding this comment

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

What makes this required?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not needed anymore since we depend on sql-action (it's redundant) so I removed it.

@@ -85,6 +88,8 @@ subprojects {
}
testCompile "org.elasticsearch.test:framework:${version}"

testCompile project(path: xpackModule('sql:sql-proto'))
Copy link
Member

Choose a reason for hiding this comment

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

What about this one?

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed as well (since everything got folded back to qa-sql).

// uncomment this to printout the result set and create new CSV tests
//
//JdbcTestUtils.logLikeCLI(elastic, log);
JdbcAssert.assertResultSets(expected, elastic, log, true);
Copy link
Member

Choose a reason for hiding this comment

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

So the headers don't have to encode the type?

Copy link
Member Author

Choose a reason for hiding this comment

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

If the lenient is set to true, the types are widened and only the values are compared.

@@ -344,7 +344,7 @@ public Object getObject(int columnIndex) throws SQLException {
throw new SQLException("type is null");
}

return getObject(columnIndex, type);
return convert(columnIndex, type);
Copy link
Member

Choose a reason for hiding this comment

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

I think this includes the jdbc fix, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that's the one (that triggers the StackOverflow).

@@ -83,17 +86,30 @@ where:
`table_name`::

Represents the name (optionally qualified) of an existing table, either a concrete or base one (actual index) or alias.


If the table name contains special SQL characters (such as `.`,`-`,etc...) use double quotes to escape them:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe worth specifying a more complete list of special characters that need escaping?

Copy link
Member Author

Choose a reason for hiding this comment

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

That needs to be a separate section (regarding the grammar in general) for a future PR.

["source","sql",subs="attributes,callouts,macros"]
----
include-tagged::{sql-specs}/docs.csv-spec[orderByScoreWithMatch]
----

NOTE:
Trying to return `score` from a non full-text queries will return the same value for all results, as
Copy link
Contributor

Choose a reason for hiding this comment

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

Small typo I believe for the query-queries: "from a non full-text queries". Should probably be singular "query" or, if using plural, "from non full-text queries".

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, "equilley" -> "equally".

@costin costin merged commit de9e56a into elastic:master Jul 3, 2018
@costin costin deleted the doc-examples branch July 3, 2018 14:24
costin added a commit that referenced this pull request Jul 3, 2018
Significantly improve the example snippets in the documentation.
The examples are part of the test suite and checked nightly.
To help readability, the existing dataset was extended (test_emp renamed
to emp plus library).
Improve output of JDBC tests to be consistent with the CLI
Add lenient flag to JDBC asserts to allow type widening (a long is
equivalent to a integer as long as the value is the same).

(cherry picked from commit de9e56a)
costin added a commit that referenced this pull request Jul 3, 2018
Significantly improve the example snippets in the documentation.
The examples are part of the test suite and checked nightly.
To help readability, the existing dataset was extended (test_emp renamed
to emp plus library).
Improve output of JDBC tests to be consistent with the CLI
Add lenient flag to JDBC asserts to allow type widening (a long is
equivalent to a integer as long as the value is the same).

(cherry picked from commit de9e56a)
(cherry picked from commit 77f5e17)
(cherry picked from commit 093ea03)
(cherry picked from commit b342552)
@costin costin added the v6.3.1 label Jul 3, 2018
dnhatn added a commit that referenced this pull request Jul 4, 2018
* 6.x:
  Fix not waiting for Netty ThreadDeathWatcher in IT (#31758) (#31789)
  [Docs] Correct default window_size (#31582)
  S3 fixture should report 404 on unknown bucket (#31782)
  [ML] Limit ML filter items to 10K (#31731)
  Fixture for Minio testing (#31688)
  [ML] Return statistics about forecasts as part of the jobsstats and usage API (#31647)
  [DOCS] Add missing get mappings docs to HLRC (#31765)
  [DOCS] Starting Elasticsearch (#31701)
  Fix coerce validation_method in GeoBoundingBoxQueryBuilder (#31747)
  Painless: Complete Removal of Painless Type (#31699)
  Consolidate watcher setting update registration (#31762)
  [DOCS] Adds empty 6.3.1 release notes page
  ingest: Introduction of a bytes processor (#31733)
  [test] don't run bats tests for suse boxes (#31749)
  Add analyze API to high-level rest client (#31577)
  Implemented XContent serialisation for GetIndexResponse (#31675)
  [DOCS] Typos
  DOC: Add examples to the SQL docs (#31633)
  Add support for AWS session tokens (#30414)
  Watcher: Reenable start/stop yaml tests (#31754)
  JDBC: Fix stackoverflow on getObject and timestamp conversion (#31735)
  Support multiple system store types (#31650)
  Add write*Blob option to replace existing blob (#31729)
  Split CircuitBreaker-related tests (#31659)
  Painless: Add Context Docs (#31190)
  Docs: Remove missing reference
  Migrate scripted metric aggregation scripts to ScriptContext design (#30111)
  Watcher: Fix chain input toXcontent serialization (#31721)
  Remove _all example (#31711)
  rest-high-level: added get cluster settings (#31706)
  Docs: Match the examples in the description (#31710)
  [Docs] Correct typos (#31720)
  Extend allowed characters for grok field names (#21745) (#31653) (#31722)
  [DOCS] Check for Windows and *nix file paths (#31648)
  [ML] Validate ML filter_id (#31535)
  Fix gradle4.8 deprecation warnings (#31654)
  Update numbers to reflect 4-byte UTF-8-encoded characters (#27083)
dnhatn added a commit that referenced this pull request Jul 4, 2018
* master:
  [ML] Rate limit established model memory updates (#31768)
  [Docs] Correct default window_size (#31582)
  S3 fixture should report 404 on unknown bucket (#31782)
  Detach Transport from TransportService (#31727)
  [ML] Limit ML filter items to 10K (#31731)
  [ML] Return statistics about forecasts as part of the jobsstats and usage API (#31647)
  Fixture for Minio testing (#31688)
  [DOCS] Add missing get mappings docs to HLRC (#31765)
  [DOCS] Starting Elasticsearch (#31701)
  Painless: Complete Removal of Painless Type (#31699)
  Fix not waiting for Netty ThreadDeathWatcher in IT (#31758)
  Consolidate watcher setting update registration (#31762)
  Build: re-enabled bwc (#31769)
  ingest: Introduction of a bytes processor (#31733)
  Fix coerce validation_method in GeoBoundingBoxQueryBuilder (#31747)
  Add analyze API to high-level rest client (#31577)
  [DOCS] Typos
  DOC: Add examples to the SQL docs (#31633)
  Add support for AWS session tokens (#30414)
  Watcher: Reenable start/stop yaml tests (#31754)
  Implemented XContent serialisation for GetIndexResponse (#31675)
  JDBC: Fix stackoverflow on getObject and timestamp conversion (#31735)
  resolveHasher defaults to NOOP (#31723)
  Account for XContent overhead in in-flight breaker
  Split CircuitBreaker-related tests (#31659)
  Add write*Blob option to replace existing blob (#31729)
  Painless: Add Context Docs (#31190)
  Watcher: Fix chain input toXcontent serialization (#31721)
  Docs: Match the examples in the description (#31710)
  rest-high-level: added get cluster settings (#31706)
  [Docs] Correct typos (#31720)
  Clean up double semicolon code typos (#31687)
  [DOCS] Check for Windows and *nix file paths (#31648)
  [ML] Validate ML filter_id (#31535)
  Revert long lines
  Fix TransportChangePasswordActionTests
@colings86 colings86 removed the v7.0.0 label Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants