diff --git a/docs/_docs/images/svg/create_table.svg b/docs/_docs/images/svg/create_table.svg new file mode 100644 index 00000000000..f34d93f9e73 --- /dev/null +++ b/docs/_docs/images/svg/create_table.svg @@ -0,0 +1,217 @@ + + + + + + + + + + + + + + CREATE + + + + + + + + TABLE + + + + + + + + + + + + + + + + IF NOT EXISTS + + + + + + + + + table_name + + + + + + + + ( + + + + + + + + + + + + + + + + pk_constraint + + + + + + + + columns_definition + + + + + + + + + + , + + + + + + + + + + ) + + + + + + + + + + + + + + + + + + + WITH + + + + + + + + + + + + + + + param_name + + + + + + + + = + + + + + + + + param_value + + + + + + + + + , + + + + + + + + + + + + diff --git a/docs/_docs/performing-transactions.adoc b/docs/_docs/performing-transactions.adoc new file mode 100644 index 00000000000..6a59b868738 --- /dev/null +++ b/docs/_docs/performing-transactions.adoc @@ -0,0 +1,46 @@ += Performing Transactions + +== Executing Transactions + +The key-value API provides an interface for starting and completing transactions. Use the `igniteTransactions` class to create a transaction object and the `commit` method to send it. + +[tabs] +-- +tab:Java[] +[source,java] +---- +Transaction tx = igniteTransactions.begin(); +tx.commit() +---- +-- + + +== Asynchronous Transactions + +You can also perform transactions asynchronously. + +[tabs] +-- +tab:Java[] +[source,java] +---- +protected Table accounts; +protected Table customers; + +accounts.recordView().upsert(null, makeValue(1, BALANCE_1)); +accounts.recordView().upsert(null, makeValue(2, BALANCE_2)); + +igniteTransactions.beginAsync() + .thenCompose(tx -> accounts.recordView().getAsync(tx, makeKey(1)) + .thenCombine(accounts.recordView().getAsync(tx, makeKey(2)), (v1, v2) -> new Pair<>(v1, v2)) + .thenCompose(pair -> allOf( + accounts.recordView().upsertAsync( + tx, makeValue(1, pair.getFirst().doubleValue("balance") - DELTA)), + accounts.recordView().upsertAsync( + tx, makeValue(2, pair.getSecond().doubleValue("balance") + DELTA)) + ) + .thenApply(ignored -> tx) + ) + ).thenCompose(Transaction::commitAsync).join(); +---- +-- \ No newline at end of file diff --git a/docs/_docs/sql/calcite-based-sql-engine.adoc b/docs/_docs/sql/calcite-based-sql-engine.adoc index 0c3a60f2722..ff684f20dad 100644 --- a/docs/_docs/sql/calcite-based-sql-engine.adoc +++ b/docs/_docs/sql/calcite-based-sql-engine.adoc @@ -25,6 +25,176 @@ Replacing H2 SQL engine with Apache Calcite incorporates the following general i * *Better optimization algorithms*: Apache Calcite optimizes queries by repeatedly applying planner rules to a relational expression; * *Higher overall performance*: Calcite offers much higher levels of execution flexibility, as well as higher efficiency in terms of both memory and CPU consumption. +== Data Definition Language (DDL) + +== CREATE TABLE + +Creates a new table. + +[source,sql] +---- +CREATE TABLE [IF NOT EXISTS] [simpleName | schemaName.simpleName] (tableColumn [, tableColumn]...) +[WITH "paramName=paramValue [,paramName=paramValue]..."] + +tableColumn = columnName columnType [[NOT] NULL] [DEFAULT defaultValue] [PRIMARY KEY] +---- + + +Parameters: + +* `tableName` - name of the table. +* `tableColumn` - name and type of a column to be created in the new table. +* `DEFAULT` - specifies a default value for the column. Only constant values are accepted. +* `IF NOT EXISTS` - create the table only if a table with the same name does not exist. +* `WITH` - accepts additional parameters not defined by ANSI-99 SQL: + +** `Replicas` - sets the number of partition copies, including the master copy. +** `Partitions` - sets the number of table partitions. + +image::images/svg/create_table.svg[Embedded,opts=inline] + + +Examples: + +Create Person table: + +[source,sql] +---- +CREATE TABLE IF NOT EXISTS Person ( + id int primary key, + city_id int, + name varchar, + age int, + company varchar, +) +---- + +== ALTER TABLE + +Modify the structure of an existing table. + +[source,sql] +---- +ALTER TABLE [IF EXISTS] tableName {alter_specification} + +alter_specification: + ADD [COLUMN] {[IF NOT EXISTS] tableColumn | (tableColumn [,...])} + | DROP [COLUMN] {[IF EXISTS] columnName | (columnName [,...])} + +tableColumn := columnName columnType +---- + +Parameters: + +- `tableName` - the name of the table. +- `tableColumn` - the name and type of the column to be added to the table. +- `IF EXISTS` - if applied to TABLE, do not throw an error if a table with the specified table name does not exist. If applied to COLUMN, do not throw an error if a column with the specified name does not exist. +- `IF NOT EXISTS` - do not throw an error if a column with the same name already exists. + + +`ALTER TABLE ADD` adds a new column or several columns to a previously created table. Once a column is added, it can be accessed by using DML commands and indexed with the CREATE INDEX statement. + +`ALTER TABLE DROP` removes an existing column or multiple columns from a table. Once a column is removed, it cannot be accessed within queries. Consider the following notes and limitations: + +Examples: + +Add a column to the table: + +[source,sql] +---- +ALTER TABLE Person ADD COLUMN city varchar; +---- + +== DROP TABLE + +The `DROP TABLE` command drops an existing table. + +[source,sql] +---- +DROP TABLE [IF EXISTS] tableName +---- + +Parameters: + +- `tableName` - the name of the table. +- `IF NOT EXISTS` - do not throw an error if a table with the same name does not exist. + + +Both DDL and DML commands targeting the same table are blocked while the `DROP TABLE` is in progress. +Once the table is dropped, all pending commands will fail with appropriate errors. + +Examples: + +Drop Person table if the one exists: + +[source,sql] +---- +DROP TABLE IF EXISTS "Person"; +---- + + +== CREATE INDEX + +Create an index on the specified table. + +[source,sql] +---- +CREATE INDEX indexName [[IF NOT EXISTS] indexName] ON tableName (columnName [ASC|DESC] [,...]) +---- + +Parameters: + +* `indexName` - the name of the index to be created. +* `ASC` - specifies ascending sort order (default). +* `DESC` - specifies descending sort order. +* `IF NOT EXISTS` - do not throw an error if an index with the same name already exists. The database checks indexes' names only, and does not consider columns types or count. + + +Examples: + +Create a regular index: + +[source,sql] +---- +CREATE INDEX title_idx ON books (title); +---- + +Create a descending index only if it does not exist: + +[source,sql] +---- +CREATE INDEX IF NOT EXISTS name_idx ON persons (firstName DESC); +---- + + +== DROP INDEX + +`DROP INDEX` deletes an existing index. + + +[source,sql] +---- +DROP INDEX [IF EXISTS] indexName +---- + +Parameters: + +* `indexName` - the name of the index to drop. +* `IF EXISTS` - do not throw an error if an index with the specified name does not exist. The database checks indexes' names only not considering column types or count. + + +DDL commands targeting the same table are blocked until `DROP INDEX` is in progress. DML command execution is not affected and can be performed in parallel. + +=== Examples + +Drop an index: + +[source,sql] +---- +DROP INDEX idx_person_name; +---- + + == Data Manipulation Language (DML) This section walks you through all data manipulation language (DML) commands supported by Apache Ignite Alpha 3.