From ca35bcee432887d2e4911ce741248376ce9ee126 Mon Sep 17 00:00:00 2001 From: Christoph Pirkl Date: Mon, 27 Sep 2021 17:46:33 +0200 Subject: [PATCH 1/7] #123: Improve documentation --- doc/changes/changes_4.4.3.md | 4 ++ .../common_constructs/value_tables.md | 8 ++- .../list_of_supported_exasol_functions.md | 27 ++++++---- doc/user_guide/rendering.md | 14 +++--- doc/user_guide/statements/create_schema.md | 6 +-- doc/user_guide/statements/create_table.md | 12 ++--- doc/user_guide/statements/drop_schema.md | 10 ++-- doc/user_guide/statements/drop_table.md | 24 ++++----- doc/user_guide/statements/insert.md | 48 +++++++++--------- doc/user_guide/statements/merge.md | 18 +++---- doc/user_guide/statements/select.md | 50 +++++++++---------- 11 files changed, 115 insertions(+), 106 deletions(-) diff --git a/doc/changes/changes_4.4.3.md b/doc/changes/changes_4.4.3.md index 8c6f8077..d4b21291 100644 --- a/doc/changes/changes_4.4.3.md +++ b/doc/changes/changes_4.4.3.md @@ -7,6 +7,10 @@ Code name: Internal refactorings on "More Predicates" * #117: Fixed sonar findings * #102: Refactored ColumnsDefinitionRenderer +## Documentation + +* #123: Improved documentation + ## Dependency Updates ### Test Dependency Updates diff --git a/doc/user_guide/common_constructs/value_tables.md b/doc/user_guide/common_constructs/value_tables.md index 613228b7..cd25cbd0 100644 --- a/doc/user_guide/common_constructs/value_tables.md +++ b/doc/user_guide/common_constructs/value_tables.md @@ -4,8 +4,6 @@ Value tables are lists of content definitions for rows. They can appear in [`INS ## Defining Value Tables -The class `ValueTable` contains multiple methods for defining value tables. - -The `appendRow()` methods allow adding all values for a complete row at once. They are especially useful in case all columns have the same type. - -The `add()` methods on the other hand amend the last row with an additional value. \ No newline at end of file +The class `ValueTable` contains multiple methods for defining value tables: +* The `appendRow()` methods allow adding all values for a complete row at once. They are especially useful in case all columns have the same type. +* The `add()` methods on the other hand amend the last row with an additional value. \ No newline at end of file diff --git a/doc/user_guide/list_of_supported_exasol_functions.md b/doc/user_guide/list_of_supported_exasol_functions.md index 5e8f3922..1e68fb86 100644 --- a/doc/user_guide/list_of_supported_exasol_functions.md +++ b/doc/user_guide/list_of_supported_exasol_functions.md @@ -3,12 +3,19 @@ Here you can find a list of supported(or partly supported) functions for the Exasol database. - [Scalar Functions](#scalar-functions) + - [Numeric Functions](#numeric-functions) + - [String Functions](#string-functions) + - [Date/Time Functions](#datetime-functions) + - [Geospatial Functions](#geospatial-functions) + - [Bitwise Function](#bitwise-function) + - [Conversion Functions](#conversion-functions) + - [Other Scalar Functions](#other-scalar-functions) - [Aggregate Functions](#aggregate-functions) - [Analytic Functions](#analytic-functions) ## Scalar Functions - -#### Numeric Functions + +### Numeric Functions - ABS - ACOS @@ -40,9 +47,9 @@ Here you can find a list of supported(or partly supported) functions for the Exa - TAN - TANH - TRUNC - -#### String Functions - + +### String Functions + - ASCII - BIT_LENGTH - CHARACTER_LENGTH @@ -81,7 +88,7 @@ Here you can find a list of supported(or partly supported) functions for the Exa - UNICODECHR - UPPER -#### Date/Time Functions +### Date/Time Functions - ADD_DAYS - ADD_HOURS @@ -117,7 +124,7 @@ Here you can find a list of supported(or partly supported) functions for the Exa - YEAR - YEARS_BETWEEN -#### Geospatial Functions +### Geospatial Functions - ST_AREA - ST_BOUNDARY @@ -160,7 +167,7 @@ Here you can find a list of supported(or partly supported) functions for the Exa - ST_X - ST_Y -#### Bitwise Function +### Bitwise Function - BIT_AND - BIT_CHECK @@ -174,7 +181,7 @@ Here you can find a list of supported(or partly supported) functions for the Exa - BIT_TO_NUM - BIT_XOR -#### Conversion Functions +### Conversion Functions - IS_NUMBER - IS_DATE @@ -189,7 +196,7 @@ Here you can find a list of supported(or partly supported) functions for the Exa - TO_TIMESTAMP - TO_YMINTERVAL -#### Other Scalar Functions +### Other Scalar Functions - COALESCE - CURRENT_SCHEMA diff --git a/doc/user_guide/rendering.md b/doc/user_guide/rendering.md index a6bb71d2..22b5204b 100644 --- a/doc/user_guide/rendering.md +++ b/doc/user_guide/rendering.md @@ -2,25 +2,25 @@ ## Creating the Renderer With Default Settings -To render an SQL statement, you need to create an instance of the SQl Statement Renderer (for example `CreateTableRenderer`) using the `create()` method of -the Renderer class. +To render an SQL statement, you need to create an instance of the SQl Statement Renderer (for example `CreateTableRenderer`) using the `create()` method of +the Renderer class: ```java -final CreateTableRenderer renderer = CreateTableRenderer.create(); +CreateTableRenderer renderer = CreateTableRenderer.create(); ``` ## Customizing Rendering -If you need more control over the rendering process, you can create you own configuration +If you need more control over the rendering process, you can create you own configuration. When you add a custom configuration, you need to pass an instance to the `create()` method. ```java -final StringRendererConfig config = StringRendererConfig.builder().lowerCase(true).build(); -final CreateTableRenderer renderer = CreateTableRenderer.create(config); +StringRendererConfig config = StringRendererConfig.builder().lowerCase(true).build(); +CreateTableRenderer renderer = CreateTableRenderer.create(config); ``` -## Rendering Statements +## Rendering Statements Next, call `accept()` method of the statement class (for example `CreateTable`) instance and pass the renderer as an argument. diff --git a/doc/user_guide/statements/create_schema.md b/doc/user_guide/statements/create_schema.md index f9ac5f5e..7b99b409 100644 --- a/doc/user_guide/statements/create_schema.md +++ b/doc/user_guide/statements/create_schema.md @@ -1,11 +1,11 @@ # CREATE SCHEMA The `CreateSchema` class of the SQL Statement Builder provides an entry -point to defining a CREATE SCHEMA SQL statement. +point to defining a [`CREATE SCHEMA`](https://docs.exasol.com/sql/create_schema.htm) SQL statement. ## Usage -1. Create an instance of the `CreateSchema` class through the `StatementFactory` +1. Create an instance of the `CreateSchema` class through the `StatementFactory`: ```java CreateSchema createSchema = StatementFactory.getInstance().createSchema("schemaName"); @@ -18,7 +18,7 @@ point to defining a CREATE SCHEMA SQL statement. ```java CreateSchema createSchema = StatementFactory.getInstance().createSchema("schemaName"); - //optional step: add config + // optional step: add configuration StringRendererConfig config = StringRendererConfig.builder().lowerCase(true).build(); CreateSchemaRenderer renderer = CreateSchemaRenderer.create(config); createSchema.accept(renderer); diff --git a/doc/user_guide/statements/create_table.md b/doc/user_guide/statements/create_table.md index 3f4f2557..417d09d7 100644 --- a/doc/user_guide/statements/create_table.md +++ b/doc/user_guide/statements/create_table.md @@ -1,11 +1,11 @@ # CREATE TABLE The `CreateTable` class of the SQL Statement Builder provides an entry -point to defining a CREATE TABLE SQL statement. +point to defining a [`CREATE TABLE`](https://docs.exasol.com/sql/create_table.htm) SQL statement. ## Usage -1. Create an instance of the `CreateTable` class through the `StatementFactory` +1. Create an instance of the `CreateTable` class through the `StatementFactory`: ```java CreateTable createTable = StatementFactory.getInstance().createTable("tableName"); @@ -42,7 +42,7 @@ point to defining a CREATE TABLE SQL statement. |``TIMESTAMP WITH LOCAL TIME ZONE``| ``false`` | `createTable.timestampWithLocalTimeZoneColumn("col_tswithzone")` | |``VARCHAR`` | ``true`` | `createTable.varcharColumn("col_varchar", 100)` | - You can find more information about the column types in the SQL Statement Builder's JavaDoc API description. + You can find more information about the column types in the SQL Statement Builder's [JavaDoc API description](https://exasol.github.io/sql-statement-builder/com/exasol/datatype/type/package-summary.html). 3. Render the instance of `CreateTable` class. Click [here](../rendering.md) for more information on Rendering SQL Statement. @@ -56,12 +56,12 @@ point to defining a CREATE TABLE SQL statement. .charColumn("col_char", 10) .booleanColumn("col_boolean"); - //optional step: add config + // optional step: add configuration StringRendererConfig config = StringRendererConfig.builder().lowerCase(true).build(); CreateTableRenderer renderer = CreateTableRenderer.create(config); createTable.accept(renderer); String renderedString = renderer.render(); ``` - -Please check [API documentation](https://exasol.github.io/sql-statement-builder/com/exasol/sql/ddl/create/CreateTable.html) for more details. \ No newline at end of file + +Please check the [API documentation](https://exasol.github.io/sql-statement-builder/com/exasol/sql/ddl/create/CreateTable.html) for more details. diff --git a/doc/user_guide/statements/drop_schema.md b/doc/user_guide/statements/drop_schema.md index a6958bd2..0199ab8a 100644 --- a/doc/user_guide/statements/drop_schema.md +++ b/doc/user_guide/statements/drop_schema.md @@ -1,7 +1,7 @@ # DROP SCHEMA The `DropSchema` class of the SQL Statement Builder provides an entry -point to defining a DROP SCHEMA SQL statement. +point to defining a [`DROP SCHEMA`](https://docs.exasol.com/sql/drop_schema.htm) SQL statement. ## Usage @@ -34,13 +34,13 @@ point to defining a DROP SCHEMA SQL statement. ```java DropSchema dropSchema = StatementFactory.getInstance().dropSchema("schemaName"); - //optional step: add additional clauses + // optional step: add additional clauses dropSchema.ifExists().cascade(); - //or + // or dropSchema.ifExists().restrict(); - //Rendering - //optional step: add config + // Rendering + // optional step: add configuration StringRendererConfig config = StringRendererConfig.builder().lowerCase(true).build(); DropSchemaRenderer renderer = DropSchemaRenderer.create(config); diff --git a/doc/user_guide/statements/drop_table.md b/doc/user_guide/statements/drop_table.md index df769944..5f394714 100644 --- a/doc/user_guide/statements/drop_table.md +++ b/doc/user_guide/statements/drop_table.md @@ -1,7 +1,7 @@ # DROP TABLE The `DropTable` class of the SQL Statement Builder provides an entry -point to defining a DROP TABLE SQL statement. +point to defining a [`DROP TABLE`](https://docs.exasol.com/sql/drop_table.htm) SQL statement. ## Usage @@ -26,19 +26,19 @@ point to defining a DROP TABLE SQL statement. 3. Render the instance of `DropTable` class. Click [here](../rendering.md) for more information on Rendering SQL Statement. - - The complete example code + The complete example code: ```java - DropTable dropTable = StatementFactory.getInstance().dropTable("tableName"); + DropTable dropTable = StatementFactory.getInstance().dropTable("tableName"); - //optional step: add additional clauses - dropTable.ifExists().cascadeConstraints(); + // optional step: add additional clauses + dropTable.ifExists().cascadeConstraints(); - //Rendering - //optional step: add config - StringRendererConfig config = StringRendererConfig.builder().lowerCase(true).build(); + // Rendering + // optional step: add configuration + StringRendererConfig config = StringRendererConfig.builder().lowerCase(true).build(); - DropTableRenderer renderer = DropTableRenderer.create(config); - dropTable.accept(renderer); - String renderedString = renderer.render(); - ``` \ No newline at end of file + DropTableRenderer renderer = DropTableRenderer.create(config); + dropTable.accept(renderer); + String renderedString = renderer.render(); + ``` \ No newline at end of file diff --git a/doc/user_guide/statements/insert.md b/doc/user_guide/statements/insert.md index 780c8672..232ba365 100644 --- a/doc/user_guide/statements/insert.md +++ b/doc/user_guide/statements/insert.md @@ -7,18 +7,18 @@ You can construct [`INSERT`](https://docs.exasol.com/sql/insert.htm) SQL stateme Create an `INSERT` statement: ```java - final Insert insert = StatementFactory.getInstance() - .insertInto("tableName") - .values("value1","value2","value3"); +Insert insert = StatementFactory.getInstance() + .insertInto("tableName") + .values("value1","value2","value3"); ``` Create an `INSERT` statement for specific fields: ```java - final Insert insert = StatementFactory.getInstance() - .insertInto("tableName") - .field("column1", "column2","column3") - .values("value1","value2","value3"); +Insert insert = StatementFactory.getInstance() + .insertInto("tableName") + .field("column1", "column2","column3") + .values("value1","value2","value3"); ``` ### Using Placeholders @@ -28,19 +28,19 @@ In SQL you can use value placeholders (`?`) in prepared statements. This allows You can add single placeholders in the following way: ```java - final Insert insert = StatementFactory.getInstance() - .insertInto("testTable") - .field("column1") - .valuePlaceholder(); +Insert insert = StatementFactory.getInstance() + .insertInto("testTable") + .field("column1") + .valuePlaceholder(); ``` Here is an example with multiple placeholders in one statement: ```java - final Insert insert = StatementFactory.getInstance() - .insertInto("testTable") - .field("column1", "column2","column3") - .valuePlaceholders(3); +Insert insert = StatementFactory.getInstance() + .insertInto("testTable") + .field("column1", "column2","column3") + .valuePlaceholders(3); ``` ### Using Value Tables @@ -48,11 +48,11 @@ Here is an example with multiple placeholders in one statement: You can also use a value table in an insert: ```java - final Insert insert = StatementFactory.getInstance().insertInto("tableName"); - final ValueTable table = new ValueTable(insert); - table.appendRow("a", "b") - .appendRow("c", "d"); - insert.valueTable(table); +Insert insert = StatementFactory.getInstance().insertInto("tableName"); +ValueTable table = new ValueTable(insert); +table.appendRow("a", "b") + .appendRow("c", "d"); +insert.valueTable(table); ``` More info on value tables [value tables](../common_constructs/value_tables.md). @@ -62,10 +62,10 @@ More info on value tables [value tables](../common_constructs/value_tables.md). Use the `InsertRenderer` to render `Insert` objects into SQL strings. ```java - final StringRendererConfig config = StringRendererConfig.builder().quoteIdentifiers(true).build(); - final InsertRenderer renderer = new InsertRenderer(config); - insert.accept(renderer); - final String sql = renderer.render(); +StringRendererConfig config = StringRendererConfig.builder().quoteIdentifiers(true).build(); +InsertRenderer renderer = new InsertRenderer(config); +insert.accept(renderer); +String sql = renderer.render(); ``` For a more general introduction please refer to ["Rendering SQL Statements into Strings"](../rendering.md). \ No newline at end of file diff --git a/doc/user_guide/statements/merge.md b/doc/user_guide/statements/merge.md index 9e43aab9..1af7c04c 100644 --- a/doc/user_guide/statements/merge.md +++ b/doc/user_guide/statements/merge.md @@ -12,7 +12,7 @@ Note that while the individual merge strategies are optional parts of the `MERGE You can create a basic `MERGE` like this: ```java -final Merge merge = StatementFactory.getInstance() +Merge merge = StatementFactory.getInstance() .merge("destination") .using("source") .on(eq(column("source", "id"), column("destination", "id"); @@ -30,10 +30,10 @@ Here is an example for `thenUpdate()`. ```java merge.whenMatched() - .thenUpdate() // - .setToDefault("c2") // - .set("c3", "foo") // - .set("c4", 42) // + .thenUpdate() + .setToDefault("c2") + .set("c3", "foo") + .set("c4", 42) .set("c5", integerLiteral(9000)); ``` @@ -61,10 +61,10 @@ All three merge strategies can be narrowed down with a `WHERE` clause, to limit Here is an example for a `MERGE` statement with a `DELETE` strategy. ```java -merge.using("src") // - .on(eq(column("src", "c1"), column("dst", "c1"))) // - .whenMatched() // - .thenDelete() // +merge.using("src") + .on(eq(column("src", "c1"), column("dst", "c1"))) + .whenMatched() + .thenDelete() .where(gt(column("src", "c5"), integerLiteral(1000))); ``` diff --git a/doc/user_guide/statements/select.md b/doc/user_guide/statements/select.md index 610d65e9..12040a7e 100644 --- a/doc/user_guide/statements/select.md +++ b/doc/user_guide/statements/select.md @@ -7,8 +7,8 @@ You can construct [`SELECT`](https://docs.exasol.com/sql/select.htm) SQL stateme You can create a basic `SELECT` like this: ```java -final Select select = StatementFactory.getInstance().select() // - .field("fieldA", "tableA.fieldB", "tableB.*"); +Select select = StatementFactory.getInstance().select() // + .field("fieldA", "tableA.fieldB", "tableB.*"); select.from().table("schemaA.tableA"); select.limit(10); ``` @@ -31,15 +31,15 @@ A `SELECT` statement can contain one or more derived columns. Here we describe a - The `field` represents a column in a table. You can create one or more fields using a method `field( ... )` of the `Select` class. ```java - final Select selectWithOneField = factory.select().field("fieldA"); + Select selectWithOneField = factory.select().field("fieldA"); - final Select selectWithMultipleFileds = factory.select().field("fieldA", "tableA.fieldB", "tableB.*"); + Select selectWithMultipleFileds = factory.select().field("fieldA", "tableA.fieldB", "tableB.*"); ``` - The `asterisk / *` is a wildcard representing all fields. Create an asterisk using the `all()` method. ```java - final Select selectWithAllFields = factory.select().all(); + Select selectWithAllFields = factory.select().all(); ``` - The factory method `function(...)` adds a pre-defined function to a statement that evaluates to a value expression. @@ -52,9 +52,9 @@ and renders them in the order they were added. The `function(...)` factory method does not validate the function arguments. ```java - final Select select = factory.select() // - .function(ExasolScalarFunction.RANDOM, "RANDOM_1") // - .function(ExasolScalarFunction.RANDOM, "RANDOM_2", ExpressionTerm.integerLiteral(5), ExpressionTerm.integerLiteral(20)); + Select select = factory.select() + .function(ExasolScalarFunction.RANDOM, "RANDOM_1") + .function(ExasolScalarFunction.RANDOM, "RANDOM_2", ExpressionTerm.integerLiteral(5), ExpressionTerm.integerLiteral(20)); ``` - The factory method `udf(...)` adds a user defined function to a statement. @@ -62,14 +62,14 @@ A udf takes a name of function and any number of [`ValueExpression`](../../../sr You can also create a udf with `EMITS` part containing column definitions. ```java - final Select selectWithoutEmits = StatementFactory.getInstance().select().udf("my_average", column("x")); - selectWithoutEmits.from().table("t"); - - final ColumnsDefinition columnsDefinition = ColumnsDefinition.builder().decimalColumn("id", 18, 0) - .varcharColumn("user_name", 100).decimalColumn("PAGE_VISITS", 18, 0).build(); - final Select selectWithEmits = StatementFactory.getInstance().select().udf("sample_simple", columnsDefinition, - column("id"), column("user_name"), column("page_visits"), integerLiteral(20)); - selectWithEmits.from().table("people"); + Select selectWithoutEmits = StatementFactory.getInstance().select().udf("my_average", column("x")); + selectWithoutEmits.from().table("t"); + + ColumnsDefinition columnsDefinition = ColumnsDefinition.builder().decimalColumn("id", 18, 0) + .varcharColumn("user_name", 100).decimalColumn("PAGE_VISITS", 18, 0).build(); + Select selectWithEmits = StatementFactory.getInstance().select().udf("sample_simple", columnsDefinition, + column("id"), column("user_name"), column("page_visits"), integerLiteral(20)); + selectWithEmits.from().table("people"); ``` - An `arithmetic expression` is a binary value expression using one of the following arithmetic operators: `+`, `-`, `*`, `/`. @@ -77,8 +77,9 @@ Add an arithmetic expression using an `arithmeticExpression( ... )` method. You can also set a name for a derived field that contains an arithmetic expression. ```java - final Select select = factory.select() // - .arithmeticExpression(ExpressionTerm.plus(ExpressionTerm.integerLiteral(1000), ExpressionTerm.integerLiteral(234)), "ADD"); + Select select = factory.select() + .arithmeticExpression(ExpressionTerm.plus(ExpressionTerm.integerLiteral(1000), ExpressionTerm.integerLiteral(234)), + "ADD"); ``` #### `FROM` clause @@ -93,15 +94,15 @@ If you want to refer to such a table by an alias, append it with `tableAs( ... You can also add value tables, containing a user-constructed set or rows and columns. Unlike a real table, the contents are pre-defined in the query. To use this structure, create a `ValueTable` object first. Then reference that object using the `valueTable( ... )` method of the `Select`. ```java -final Select selectFromTable = factory.select().all(); +Select selectFromTable = factory.select().all(); selectFromTable.from().table("table1"); -final Select selectFromTableAs = factory.select().all(); +Select selectFromTableAs = factory.select().all(); selectFromTableAs.from().tableAs("table", "t"); -final ValueTable values = new ValueTable(this.select); +ValueTable values = new ValueTable(this.select); values.appendRow("r1c1", "r1c2").appendRow("r2c1", "r2c2"); -final Select selectFromValueTable = factory.select().all(); +Select selectFromValueTable = factory.select().all(); selectFromValueTable.from().valueTable(values); ``` @@ -119,8 +120,8 @@ The `FROM` clause also supports different types of `JOIN`: To add a `JOIN` clause you need to add a left table and then use one of the join methods. For example, `innerJoin( ... )`; ```java -final Select selectFromTable = factory.select().all(); -selectFromTable.from().table("left_table") // +Select selectFromTable = factory.select().all(); +selectFromTable.from().table("left_table") .innerJoin("right_table", "left_table.foo_id = right_table.foo_id"); ``` #### `WHERE` clause @@ -166,7 +167,6 @@ A `SELECT` statement can contain one `ORDER BY` clause. To start a `ORDER BY` clause, use the `orderBy()` method of the `Select` class. You can also use `nullsFirst()`/`nullsLast()` and `asc()`/`desc()` methods within this clause. - ```java Select select = factory.select().all(); select.from().table("t"); From 363634885ad26d1413744a450d884ec11448c6dd Mon Sep 17 00:00:00 2001 From: Christoph Pirkl Date: Mon, 27 Sep 2021 17:49:10 +0200 Subject: [PATCH 2/7] Use correct project abbreviation --- doc/user_guide/statements/select.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/user_guide/statements/select.md b/doc/user_guide/statements/select.md index 12040a7e..29ec9943 100644 --- a/doc/user_guide/statements/select.md +++ b/doc/user_guide/statements/select.md @@ -43,7 +43,7 @@ A `SELECT` statement can contain one or more derived columns. Here we describe a ``` - The factory method `function(...)` adds a pre-defined function to a statement that evaluates to a value expression. -You can only create functions that the SSB supports. Check [the list of supported functions](../list_of_supported_exasol_functions.md). +You can only create functions that the ESB supports. Check [the list of supported functions](../list_of_supported_exasol_functions.md). You can also set a name for a derived field that contains a function. A function takes any number of [`ValueExpression`](../../../src/main/java/com/exasol/sql/expression/ValueExpression.java)s From dbb932cf310be52f1a4cb3c679b94302d84e6804 Mon Sep 17 00:00:00 2001 From: Christoph Pirkl Date: Mon, 27 Sep 2021 17:50:50 +0200 Subject: [PATCH 3/7] Cleanup code examples --- README.md | 10 +++++----- doc/user_guide/statements/select.md | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 920a9534..9f7964ce 100644 --- a/README.md +++ b/README.md @@ -32,14 +32,14 @@ Goals: The following example gives you an idea about what you can do with the SQL Statement Builder. Check our [user guide](doc/user_guide/user_guide.md) for more details. ```java -final Select select = StatementFactory.getInstance().select() // - .field("fieldA", "tableA.fieldB", "tableB.*"); +Select select = StatementFactory.getInstance().select() + .field("fieldA", "tableA.fieldB", "tableB.*"); select.from().table("schemaA.tableA"); select.limit(10); -final StringRendererConfig config = StringRendererConfig.builder().quoteIdentifiers(true).build(); -final SelectRenderer renderer = new SelectRenderer(config); +StringRendererConfig config = StringRendererConfig.builder().quoteIdentifiers(true).build(); +SelectRenderer renderer = new SelectRenderer(config); select.accept(renderer); -final String sql = renderer.render(); +String sql = renderer.render(); ``` ## Table of Contents diff --git a/doc/user_guide/statements/select.md b/doc/user_guide/statements/select.md index 29ec9943..c5014f5a 100644 --- a/doc/user_guide/statements/select.md +++ b/doc/user_guide/statements/select.md @@ -7,7 +7,7 @@ You can construct [`SELECT`](https://docs.exasol.com/sql/select.htm) SQL stateme You can create a basic `SELECT` like this: ```java -Select select = StatementFactory.getInstance().select() // +Select select = StatementFactory.getInstance().select() .field("fieldA", "tableA.fieldB", "tableB.*"); select.from().table("schemaA.tableA"); select.limit(10); From 1b89a63873d73308047c9d373592e0b2e59f681f Mon Sep 17 00:00:00 2001 From: Christoph Pirkl Date: Mon, 27 Sep 2021 17:57:23 +0200 Subject: [PATCH 4/7] Remove trailing spaces --- doc/system_requirements.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/system_requirements.md b/doc/system_requirements.md index 1a3f89c1..563d3098 100644 --- a/doc/system_requirements.md +++ b/doc/system_requirements.md @@ -373,11 +373,11 @@ ESB supports the following `SELECT` statement: derived-column = expression [as-clause] - expression = arithmetic-expression / column-reference / function + expression = arithmetic-expression / column-reference / function table-expression = from-clause [where-clause] [limit-clause] [group-by-clause] [order-by-clause] - from-clause = "FROM" table-reference + from-clause = "FROM" table-reference where-clause = "WHERE" boolean-term From ce458de6134b3db2656a1d52f4a16fc135b61bf3 Mon Sep 17 00:00:00 2001 From: Christoph Pirkl Date: Mon, 27 Sep 2021 18:22:53 +0200 Subject: [PATCH 5/7] Improve formatting --- doc/user_guide/statements/select.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/user_guide/statements/select.md b/doc/user_guide/statements/select.md index c5014f5a..fc709733 100644 --- a/doc/user_guide/statements/select.md +++ b/doc/user_guide/statements/select.md @@ -165,7 +165,7 @@ select.groupBy(column("t", "city"), column("t", "order"), column("t", "price")) A `SELECT` statement can contain one `ORDER BY` clause. To start a `ORDER BY` clause, use the `orderBy()` method of the `Select` class. -You can also use `nullsFirst()`/`nullsLast()` and `asc()`/`desc()` methods within this clause. +You can also use `nullsFirst()` / `nullsLast()` and `asc()` / `desc()` methods within this clause. ```java Select select = factory.select().all(); From 70173f4900b1bd8d91d00e7a51fdd08a256c8eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ch=CF=80?= Date: Tue, 28 Sep 2021 10:56:30 +0200 Subject: [PATCH 6/7] Apply suggestions from code review Co-authored-by: Anastasiia Sergienko <46891819+AnastasiiaSergienko@users.noreply.github.com> --- doc/user_guide/rendering.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/user_guide/rendering.md b/doc/user_guide/rendering.md index 22b5204b..ea206076 100644 --- a/doc/user_guide/rendering.md +++ b/doc/user_guide/rendering.md @@ -2,7 +2,7 @@ ## Creating the Renderer With Default Settings -To render an SQL statement, you need to create an instance of the SQl Statement Renderer (for example `CreateTableRenderer`) using the `create()` method of +To render an SQL statement, you need to create an instance of the SQL Statement Renderer (for example `CreateTableRenderer`) using the `create()` method of the Renderer class: ```java From 82c26cf3ffb02dca9938fc61d309b28c2d9e27b6 Mon Sep 17 00:00:00 2001 From: Christoph Pirkl Date: Tue, 28 Sep 2021 11:08:55 +0200 Subject: [PATCH 7/7] Implement review findings: remove hard line wraps --- doc/user_guide/rendering.md | 6 ++---- doc/user_guide/statements/create_schema.md | 3 +-- doc/user_guide/statements/create_table.md | 7 ++----- doc/user_guide/statements/drop_schema.md | 6 ++---- doc/user_guide/statements/drop_table.md | 3 +-- doc/user_guide/statements/merge.md | 3 +-- doc/user_guide/statements/select.md | 24 ++++++++-------------- 7 files changed, 17 insertions(+), 35 deletions(-) diff --git a/doc/user_guide/rendering.md b/doc/user_guide/rendering.md index ea206076..b66a6466 100644 --- a/doc/user_guide/rendering.md +++ b/doc/user_guide/rendering.md @@ -2,8 +2,7 @@ ## Creating the Renderer With Default Settings -To render an SQL statement, you need to create an instance of the SQL Statement Renderer (for example `CreateTableRenderer`) using the `create()` method of -the Renderer class: +To render an SQL statement, you need to create an instance of the SQL Statement Renderer (for example `CreateTableRenderer`) using the `create()` method of the Renderer class: ```java CreateTableRenderer renderer = CreateTableRenderer.create(); @@ -22,8 +21,7 @@ CreateTableRenderer renderer = CreateTableRenderer.create(config); ## Rendering Statements -Next, call `accept()` method of the statement class (for example `CreateTable`) instance and pass the renderer as -an argument. +Next, call `accept()` method of the statement class (for example `CreateTable`) instance and pass the renderer as an argument. ```java createTable.accept(renderer); diff --git a/doc/user_guide/statements/create_schema.md b/doc/user_guide/statements/create_schema.md index 7b99b409..073cc262 100644 --- a/doc/user_guide/statements/create_schema.md +++ b/doc/user_guide/statements/create_schema.md @@ -1,7 +1,6 @@ # CREATE SCHEMA -The `CreateSchema` class of the SQL Statement Builder provides an entry -point to defining a [`CREATE SCHEMA`](https://docs.exasol.com/sql/create_schema.htm) SQL statement. +The `CreateSchema` class of the SQL Statement Builder provides an entry point to defining a [`CREATE SCHEMA`](https://docs.exasol.com/sql/create_schema.htm) SQL statement. ## Usage diff --git a/doc/user_guide/statements/create_table.md b/doc/user_guide/statements/create_table.md index 417d09d7..cdc1ced6 100644 --- a/doc/user_guide/statements/create_table.md +++ b/doc/user_guide/statements/create_table.md @@ -1,7 +1,6 @@ # CREATE TABLE -The `CreateTable` class of the SQL Statement Builder provides an entry -point to defining a [`CREATE TABLE`](https://docs.exasol.com/sql/create_table.htm) SQL statement. +The `CreateTable` class of the SQL Statement Builder provides an entry point to defining a [`CREATE TABLE`](https://docs.exasol.com/sql/create_table.htm) SQL statement. ## Usage @@ -23,9 +22,7 @@ point to defining a [`CREATE TABLE`](https://docs.exasol.com/sql/create_table.ht .booleanColumn("col_boolean"); ``` - Please keep in mind that the column name is required when creating a column. - Additionally, some column types require extra parameters, for instance - `VARCHAR`. + Please keep in mind that the column name is required when creating a column. Additionally, some column types require extra parameters, for instance `VARCHAR`. **Currently, the following column types are supported:** diff --git a/doc/user_guide/statements/drop_schema.md b/doc/user_guide/statements/drop_schema.md index 0199ab8a..0869019e 100644 --- a/doc/user_guide/statements/drop_schema.md +++ b/doc/user_guide/statements/drop_schema.md @@ -1,7 +1,6 @@ # DROP SCHEMA -The `DropSchema` class of the SQL Statement Builder provides an entry -point to defining a [`DROP SCHEMA`](https://docs.exasol.com/sql/drop_schema.htm) SQL statement. +The `DropSchema` class of the SQL Statement Builder provides an entry point to defining a [`DROP SCHEMA`](https://docs.exasol.com/sql/drop_schema.htm) SQL statement. ## Usage @@ -24,8 +23,7 @@ point to defining a [`DROP SCHEMA`](https://docs.exasol.com/sql/drop_schema.htm) ```java dropSchema.ifExists().cascade(); ``` - Please do not use methods `cascade()` and `restrict()` on the same object. - If both these options are used on the same object, `IllegalArgumentException` will be thrown. + Please do not use methods `cascade()` and `restrict()` on the same object. If both these options are used on the same object, `IllegalArgumentException` will be thrown. 3. Render the instance of `DropSchema` class. Click [here](../rendering.md) for more information on Rendering SQL Statement. diff --git a/doc/user_guide/statements/drop_table.md b/doc/user_guide/statements/drop_table.md index 5f394714..4ae9d8b2 100644 --- a/doc/user_guide/statements/drop_table.md +++ b/doc/user_guide/statements/drop_table.md @@ -1,7 +1,6 @@ # DROP TABLE -The `DropTable` class of the SQL Statement Builder provides an entry -point to defining a [`DROP TABLE`](https://docs.exasol.com/sql/drop_table.htm) SQL statement. +The `DropTable` class of the SQL Statement Builder provides an entry point to defining a [`DROP TABLE`](https://docs.exasol.com/sql/drop_table.htm) SQL statement. ## Usage diff --git a/doc/user_guide/statements/merge.md b/doc/user_guide/statements/merge.md index 1af7c04c..6add5fce 100644 --- a/doc/user_guide/statements/merge.md +++ b/doc/user_guide/statements/merge.md @@ -2,8 +2,7 @@ You can construct [`MERGE`](https://docs.exasol.com/sql/merge.htm) SQL statements using the `Merge` class. -`Merge` supports a combination of `INSERT`, `UPDATE` and `DELETE` where source data is merged into a destination table. The merge strategy is configurable and depends on whether or not a row in source and destination are considered a match. -Of course the criteria for that match is configurable too. +`Merge` supports a combination of `INSERT`, `UPDATE` and `DELETE` where source data is merged into a destination table. The merge strategy is configurable and depends on whether or not a row in source and destination are considered a match. Of course the criteria for that match is configurable too. Note that while the individual merge strategies are optional parts of the `MERGE` statement, you need to pick *at least one* to get a valid statement. diff --git a/doc/user_guide/statements/select.md b/doc/user_guide/statements/select.md index fc709733..c29e6a23 100644 --- a/doc/user_guide/statements/select.md +++ b/doc/user_guide/statements/select.md @@ -46,8 +46,7 @@ A `SELECT` statement can contain one or more derived columns. Here we describe a You can only create functions that the ESB supports. Check [the list of supported functions](../list_of_supported_exasol_functions.md). You can also set a name for a derived field that contains a function. -A function takes any number of [`ValueExpression`](../../../src/main/java/com/exasol/sql/expression/ValueExpression.java)s -and renders them in the order they were added. +A function takes any number of [`ValueExpression`](../../../src/main/java/com/exasol/sql/expression/ValueExpression.java)s and renders them in the order they were added. The `function(...)` factory method does not validate the function arguments. @@ -58,8 +57,7 @@ and renders them in the order they were added. ``` - The factory method `udf(...)` adds a user defined function to a statement. -A udf takes a name of function and any number of [`ValueExpression`](../../../src/main/java/com/exasol/sql/expression/ValueExpression.java)s. -You can also create a udf with `EMITS` part containing column definitions. +A udf takes a name of function and any number of [`ValueExpression`](../../../src/main/java/com/exasol/sql/expression/ValueExpression.java)s. You can also create a udf with `EMITS` part containing column definitions. ```java Select selectWithoutEmits = StatementFactory.getInstance().select().udf("my_average", column("x")); @@ -73,8 +71,7 @@ You can also create a udf with `EMITS` part containing column definitions. ``` - An `arithmetic expression` is a binary value expression using one of the following arithmetic operators: `+`, `-`, `*`, `/`. -Add an arithmetic expression using an `arithmeticExpression( ... )` method. -You can also set a name for a derived field that contains an arithmetic expression. +Add an arithmetic expression using an `arithmeticExpression( ... )` method. You can also set a name for a derived field that contains an arithmetic expression. ```java Select select = factory.select() @@ -84,8 +81,7 @@ You can also set a name for a derived field that contains an arithmetic expressi #### `FROM` clause -A `SELECT` statement can contain a single `FROM` clause. -To start a `FROM` clause, use a method `from()` of the `Select` class. +A `SELECT` statement can contain a single `FROM` clause. To start a `FROM` clause, use a method `from()` of the `Select` class. You can append references to database tables with the `table( ... )` method. @@ -126,8 +122,7 @@ selectFromTable.from().table("left_table") ``` #### `WHERE` clause -A `SELECT` statement can contain one `WHERE` clause with a boolean expression as filter criteria. -To add a `WHERE` clause, use a method `where( ... )` of the `Select` class. +A `SELECT` statement can contain one `WHERE` clause with a boolean expression as filter criteria. To add a `WHERE` clause, use a method `where( ... )` of the `Select` class. ```java Select select = factory.select.all(); @@ -137,8 +132,7 @@ select.where(eq(ExpressionTerm.stringLiteral("foo"), ExpressionTerm.stringLitera #### `LIMIT` clause -A `SELECT` statement can contain one `LIMIT` clause with count and an optional offset. -To add a `LIMIT` clause, use a method `limit( ... )` of the `Select` class. +A `SELECT` statement can contain one `LIMIT` clause with count and an optional offset. To add a `LIMIT` clause, use a method `limit( ... )` of the `Select` class. ```java Select select = factory.select().all(); @@ -148,8 +142,7 @@ select.limit(1); #### `GROUP BY` clause -A `SELECT` statement can contain one `GROUP BY` clause. -To start a `GROUP BY` clause, use the `groupBy()` method of the `Select` class. +A `SELECT` statement can contain one `GROUP BY` clause. To start a `GROUP BY` clause, use the `groupBy()` method of the `Select` class. The `GROUP BY` clause supports a `HAVING` clause. To add it use a `having( ... )` method. @@ -164,8 +157,7 @@ select.groupBy(column("t", "city"), column("t", "order"), column("t", "price")) A `SELECT` statement can contain one `ORDER BY` clause. -To start a `ORDER BY` clause, use the `orderBy()` method of the `Select` class. -You can also use `nullsFirst()` / `nullsLast()` and `asc()` / `desc()` methods within this clause. +To start a `ORDER BY` clause, use the `orderBy()` method of the `Select` class. You can also use `nullsFirst()` / `nullsLast()` and `asc()` / `desc()` methods within this clause. ```java Select select = factory.select().all();