JAkutenshi commented on code in PR #6585: URL: https://github.com/apache/ignite-3/pull/6585#discussion_r2348802223
########## examples/java/src/main/java/org/apache/ignite/example/table/TableExample.java: ########## @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.example.table; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.Statement; +import java.util.List; +import org.apache.ignite.client.IgniteClient; +import org.apache.ignite.table.IgniteTables; +import org.apache.ignite.table.KeyValueView; +import org.apache.ignite.table.QualifiedName; +import org.apache.ignite.table.Table; +import org.apache.ignite.table.Tuple; + +/** + * This example demonstrates the usage of the {@link KeyValueView} API. + * + * <p>Find instructions on how to run the example in the README.md file located in the "examples" directory root. + */ +public class TableExample { + /** + * Main method of the example. + * + * @param args The command line arguments. + * @throws Exception If failed. + */ + public static void main(String[] args) throws Exception { + + try (IgniteClient client = IgniteClient.builder() + .addresses("127.0.0.1:10800") + .build() + ) { + // Create a table to work with later + client.sql().execute(null, "CREATE TABLE IF NOT EXISTS Person (" + + "id int primary key," + + "city_id int," + + "name varchar," + + "age int," + + "company varchar" + ); + + // Get the tables API to interact with database tables + IgniteTables tableApi = client.tables(); + + // Retrieve a list of all existing tables in the cluster + //List<Table> existingTables = tableApi.tables(); + + // Get the first table from the list (for demonstration purposes) + //Table firstTable = existingTables.get(0); + + // Access a specific table by its simple name + //Table specificTable = tableApi.table("MY_TABLE"); + + // Create a qualified table name by parsing a string (schema.table format) + QualifiedName qualifiedTableName = QualifiedName.parse("PUBLIC.MY_QUALIFIED_TABLE"); Review Comment: If I run this main, thus there no `MY_QUALIFIED_TABLE` table, only `Person`, so `myTable.recordView().insert(null, personTuple) below will lead to NPE. ########## examples/java/src/main/java/org/apache/ignite/example/table/TableExample.java: ########## @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.example.table; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.Statement; +import java.util.List; +import org.apache.ignite.client.IgniteClient; +import org.apache.ignite.table.IgniteTables; +import org.apache.ignite.table.KeyValueView; +import org.apache.ignite.table.QualifiedName; +import org.apache.ignite.table.Table; +import org.apache.ignite.table.Tuple; + +/** + * This example demonstrates the usage of the {@link KeyValueView} API. + * + * <p>Find instructions on how to run the example in the README.md file located in the "examples" directory root. + */ +public class TableExample { + /** + * Main method of the example. + * + * @param args The command line arguments. + * @throws Exception If failed. + */ + public static void main(String[] args) throws Exception { + + try (IgniteClient client = IgniteClient.builder() + .addresses("127.0.0.1:10800") + .build() + ) { + // Create a table to work with later + client.sql().execute(null, "CREATE TABLE IF NOT EXISTS Person (" + + "id int primary key," + + "city_id int," + + "name varchar," + + "age int," + + "company varchar" + ); + + // Get the tables API to interact with database tables + IgniteTables tableApi = client.tables(); + + // Retrieve a list of all existing tables in the cluster + //List<Table> existingTables = tableApi.tables(); + + // Get the first table from the list (for demonstration purposes) + //Table firstTable = existingTables.get(0); + + // Access a specific table by its simple name + //Table specificTable = tableApi.table("MY_TABLE"); + + // Create a qualified table name by parsing a string (schema.table format) + QualifiedName qualifiedTableName = QualifiedName.parse("PUBLIC.MY_QUALIFIED_TABLE"); + + // Alternative way to create qualified name using schema and table parts + //QualifiedName qualifiedTableName = QualifiedName.of("PUBLIC", "MY_TABLE"); + + // Access a table using the qualified name (includes schema) + Table myTable = tableApi.table(qualifiedTableName); + + Tuple personTuple = Tuple.create() + .set("id", 1) + .set("cityId", "3") Review Comment: `city_id`? Schema mismatch. Also the value should be `int`. ########## examples/java/src/main/java/org/apache/ignite/example/table/TableExample.java: ########## @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.example.table; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.Statement; +import java.util.List; +import org.apache.ignite.client.IgniteClient; +import org.apache.ignite.table.IgniteTables; +import org.apache.ignite.table.KeyValueView; +import org.apache.ignite.table.QualifiedName; +import org.apache.ignite.table.Table; +import org.apache.ignite.table.Tuple; + +/** + * This example demonstrates the usage of the {@link KeyValueView} API. + * + * <p>Find instructions on how to run the example in the README.md file located in the "examples" directory root. + */ +public class TableExample { + /** + * Main method of the example. + * + * @param args The command line arguments. + * @throws Exception If failed. + */ + public static void main(String[] args) throws Exception { + + try (IgniteClient client = IgniteClient.builder() + .addresses("127.0.0.1:10800") + .build() + ) { + // Create a table to work with later + client.sql().execute(null, "CREATE TABLE IF NOT EXISTS Person (" + + "id int primary key," + + "city_id int," + + "name varchar," + + "age int," + + "company varchar" Review Comment: Missed close parenthesis `)` that leads to SQL exception ########## examples/java/src/main/java/org/apache/ignite/example/table/MapperExample.java: ########## @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.example.table; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import org.apache.ignite.client.IgniteClient; +import org.apache.ignite.table.RecordView; +import org.apache.ignite.table.Tuple; +import org.apache.ignite.table.mapper.Mapper; +import org.apache.ignite.table.mapper.TypeConverter; + +public class MapperExample { + static class BinaryTypeConverter implements TypeConverter<Person, byte[]> { + + @Override + public Person toObjectType(byte[] bytes) throws IOException, ClassNotFoundException { + try (var in = new ObjectInputStream(new ByteArrayInputStream(bytes))) { + return (Person) in.readObject(); + } + } + + @Override + public byte[] toColumnType(Person person) throws IOException { + try (var bos = new ByteArrayOutputStream(); + var out = new ObjectOutputStream(bos)) { + out.writeObject(person); + return bos.toByteArray(); + } + } + } + + + public static void main(String[] args) throws Exception { + var mapper = Mapper.builder(Person.class) + .automap() + .map("city", "city", new BinaryTypeConverter()) Review Comment: In `TableExample` column is named as `city_id`, this will ead to an exception for a user. Moreover in `Person` there is no `city` field, but `cityId` ########## examples/java/src/main/java/org/apache/ignite/example/table/TableExample.java: ########## @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.example.table; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.Statement; +import java.util.List; +import org.apache.ignite.client.IgniteClient; +import org.apache.ignite.table.IgniteTables; +import org.apache.ignite.table.KeyValueView; +import org.apache.ignite.table.QualifiedName; +import org.apache.ignite.table.Table; +import org.apache.ignite.table.Tuple; + +/** + * This example demonstrates the usage of the {@link KeyValueView} API. + * + * <p>Find instructions on how to run the example in the README.md file located in the "examples" directory root. + */ +public class TableExample { + /** + * Main method of the example. + * + * @param args The command line arguments. + * @throws Exception If failed. + */ + public static void main(String[] args) throws Exception { + + try (IgniteClient client = IgniteClient.builder() + .addresses("127.0.0.1:10800") + .build() + ) { + // Create a table to work with later + client.sql().execute(null, "CREATE TABLE IF NOT EXISTS Person (" + + "id int primary key," + + "city_id int," + + "name varchar," + + "age int," + + "company varchar" + ); + + // Get the tables API to interact with database tables + IgniteTables tableApi = client.tables(); + + // Retrieve a list of all existing tables in the cluster + //List<Table> existingTables = tableApi.tables(); + + // Get the first table from the list (for demonstration purposes) + //Table firstTable = existingTables.get(0); + + // Access a specific table by its simple name + //Table specificTable = tableApi.table("MY_TABLE"); + + // Create a qualified table name by parsing a string (schema.table format) + QualifiedName qualifiedTableName = QualifiedName.parse("PUBLIC.MY_QUALIFIED_TABLE"); + + // Alternative way to create qualified name using schema and table parts + //QualifiedName qualifiedTableName = QualifiedName.of("PUBLIC", "MY_TABLE"); + + // Access a table using the qualified name (includes schema) + Table myTable = tableApi.table(qualifiedTableName); + + Tuple personTuple = Tuple.create() + .set("id", 1) + .set("cityId", "3") + .set("name", "John") + .set("age", 32) + .set("company", ""); + + myTable.recordView().insert(null, personTuple); Review Comment: I'd to suggest the follow ending: ```java RecordView<Tuple> personTableView = myTable.recordView(); Tuple personTuple = Tuple.create() .set("id", 1) .set("city_id", 3) .set("name", "John") .set("age", 32) .set("company", ""); personTableView.insert(null, personTuple); Tuple personIdTuple = Tuple.create() .set("id", 1); Tuple insertedPerson = personTableView.get(null, personIdTuple); System.out.println("Person name: " + insertedPerson.stringValue("name")); ``` This will explicit the view object and assert that the tuple was inserted successfully. ########## examples/java/src/main/java/org/apache/ignite/example/table/QueryExample.java: ########## @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.example.table; + +import static org.apache.ignite.table.criteria.Criteria.and; +import static org.apache.ignite.table.criteria.Criteria.columnValue; +import static org.apache.ignite.table.criteria.Criteria.equalTo; +import static org.apache.ignite.table.criteria.Criteria.greaterThan; + +import java.util.Iterator; +import java.util.Map.Entry; +import org.apache.ignite.client.IgniteClient; +import org.apache.ignite.lang.AsyncCursor; +import org.apache.ignite.lang.Cursor; +import org.apache.ignite.table.IgniteTables; +import org.apache.ignite.table.Table; +import org.apache.ignite.table.Tuple; +import org.apache.ignite.tx.Transaction; + +public class QueryExample { + + public static void main(String[] args) throws Exception { + // Initialize Ignite client with connection configuration + try (IgniteClient client = IgniteClient.builder() + .addresses("127.0.0.1:10800") + .build()) { + + // Get a table + IgniteTables tablesApi = client.tables(); + Table myTable = tablesApi.table("MY_TABLE"); + + // Example 1: Query without transaction + performQueryWithoutTransaction(myTable); + + // Example 2: Query within transaction + performQueryWithTransaction(client, myTable); + + // Example 3: Query asynchronously + performQueryAsync(myTable); + } + } + + /** + * Demonstrates querying with an implicit transaction. + */ + public static void performQueryWithoutTransaction(Table table) { + try (Cursor<Entry<Tuple, Tuple>> cursor = table.keyValueView().query( + null, // Implicit transaction + // Query criteria + and( + columnValue("name", equalTo("John Doe")), + columnValue("age", greaterThan(20)) + ) + )) { + // Process query results (keeping original cursor iteration pattern) + // As an example, remove the first found value. + cursor.remove(); Review Comment: `.remove()` this and below will return `UnsupportedOperationException` because of modification is forbidden. I suggest just println the result set. Moreover if you're running after `TableExamples` then there no `John Doe` record, just `John`, so the cursor has no values. Make it consistent. ########## examples/java/src/main/java/org/apache/ignite/example/table/TableExample.java: ########## @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.example.table; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.Statement; +import java.util.List; +import org.apache.ignite.client.IgniteClient; +import org.apache.ignite.table.IgniteTables; +import org.apache.ignite.table.KeyValueView; +import org.apache.ignite.table.QualifiedName; +import org.apache.ignite.table.Table; +import org.apache.ignite.table.Tuple; + +/** + * This example demonstrates the usage of the {@link KeyValueView} API. + * + * <p>Find instructions on how to run the example in the README.md file located in the "examples" directory root. + */ +public class TableExample { + /** + * Main method of the example. + * + * @param args The command line arguments. + * @throws Exception If failed. + */ + public static void main(String[] args) throws Exception { + + try (IgniteClient client = IgniteClient.builder() + .addresses("127.0.0.1:10800") + .build() + ) { + // Create a table to work with later + client.sql().execute(null, "CREATE TABLE IF NOT EXISTS Person (" + + "id int primary key," + + "city_id int," + + "name varchar," + + "age int," + + "company varchar" + ); + + // Get the tables API to interact with database tables + IgniteTables tableApi = client.tables(); + + // Retrieve a list of all existing tables in the cluster + //List<Table> existingTables = tableApi.tables(); + + // Get the first table from the list (for demonstration purposes) + //Table firstTable = existingTables.get(0); + + // Access a specific table by its simple name + //Table specificTable = tableApi.table("MY_TABLE"); + + // Create a qualified table name by parsing a string (schema.table format) + QualifiedName qualifiedTableName = QualifiedName.parse("PUBLIC.MY_QUALIFIED_TABLE"); + + // Alternative way to create qualified name using schema and table parts + //QualifiedName qualifiedTableName = QualifiedName.of("PUBLIC", "MY_TABLE"); + + // Access a table using the qualified name (includes schema) + Table myTable = tableApi.table(qualifiedTableName); + + Tuple personTuple = Tuple.create() + .set("id", 1) + .set("cityId", "3") + .set("name", "John") + .set("age", 32) + .set("company", ""); + + myTable.recordView().insert(null, personTuple); Review Comment: Also i'd like to replace `insert` as `upsert` that makes the example idempotent. ########## examples/java/src/main/java/org/apache/ignite/example/table/Person.java: ########## @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.example.table; + +/** + * Represents a Person entity with database mapping. + * + * Database schema: + * - id: int PRIMARY KEY + * - city_id: int + * - name: varchar + * - age: int + * - company: varchar + */ +public class Person { + private int id; + private int cityId; Review Comment: Due to the `MapperExample` commentary, I would suggest make it `String` there. ########## examples/java/src/main/java/org/apache/ignite/example/table/QueryExample.java: ########## @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.example.table; + +import static org.apache.ignite.table.criteria.Criteria.and; +import static org.apache.ignite.table.criteria.Criteria.columnValue; +import static org.apache.ignite.table.criteria.Criteria.equalTo; +import static org.apache.ignite.table.criteria.Criteria.greaterThan; + +import java.util.Iterator; +import java.util.Map.Entry; +import org.apache.ignite.client.IgniteClient; +import org.apache.ignite.lang.AsyncCursor; +import org.apache.ignite.lang.Cursor; +import org.apache.ignite.table.IgniteTables; +import org.apache.ignite.table.Table; +import org.apache.ignite.table.Tuple; +import org.apache.ignite.tx.Transaction; + +public class QueryExample { + + public static void main(String[] args) throws Exception { + // Initialize Ignite client with connection configuration + try (IgniteClient client = IgniteClient.builder() + .addresses("127.0.0.1:10800") + .build()) { + + // Get a table + IgniteTables tablesApi = client.tables(); + Table myTable = tablesApi.table("MY_TABLE"); Review Comment: There is no such table, do you mean `person`? ########## examples/java/src/main/java/org/apache/ignite/example/table/MapperExample.java: ########## @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.example.table; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import org.apache.ignite.client.IgniteClient; +import org.apache.ignite.table.RecordView; +import org.apache.ignite.table.Tuple; +import org.apache.ignite.table.mapper.Mapper; +import org.apache.ignite.table.mapper.TypeConverter; + +public class MapperExample { + static class BinaryTypeConverter implements TypeConverter<Person, byte[]> { Review Comment: You're doing there something strange. The mapper maps your unknown (or unmatched) type of value to table's type. E.g. you in `TableExample` tried to put `String` value as `city_id`, so this is a good example: you implement this with `<String, Integer>` generic types for your field `cityId`: ```java static class CityIdConverter implements TypeConverter<String, Integer> { @Override public String toObjectType(Integer columnValue) { return columnValue.toString(); } @Override public Integer toColumnType(String cityId) { return Integer.parseInt(cityId); } } ``` ...and this will work. Your example will fail, because internals will try to map `city_id` as a number, but mapper will expect `Person` type and will throw `ClassCastException`. ########## examples/java/src/main/java/org/apache/ignite/example/table/TableExample.java: ########## @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.example.table; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.Statement; +import java.util.List; +import org.apache.ignite.client.IgniteClient; +import org.apache.ignite.table.IgniteTables; +import org.apache.ignite.table.KeyValueView; +import org.apache.ignite.table.QualifiedName; +import org.apache.ignite.table.Table; +import org.apache.ignite.table.Tuple; + +/** + * This example demonstrates the usage of the {@link KeyValueView} API. + * + * <p>Find instructions on how to run the example in the README.md file located in the "examples" directory root. + */ +public class TableExample { + /** + * Main method of the example. + * + * @param args The command line arguments. + * @throws Exception If failed. + */ + public static void main(String[] args) throws Exception { + + try (IgniteClient client = IgniteClient.builder() + .addresses("127.0.0.1:10800") + .build() + ) { + // Create a table to work with later + client.sql().execute(null, "CREATE TABLE IF NOT EXISTS Person (" + + "id int primary key," + + "city_id int," + + "name varchar," + + "age int," + + "company varchar" + ); + + // Get the tables API to interact with database tables + IgniteTables tableApi = client.tables(); + + // Retrieve a list of all existing tables in the cluster + //List<Table> existingTables = tableApi.tables(); + + // Get the first table from the list (for demonstration purposes) + //Table firstTable = existingTables.get(0); + + // Access a specific table by its simple name + //Table specificTable = tableApi.table("MY_TABLE"); + + // Create a qualified table name by parsing a string (schema.table format) + QualifiedName qualifiedTableName = QualifiedName.parse("PUBLIC.MY_QUALIFIED_TABLE"); + + // Alternative way to create qualified name using schema and table parts + //QualifiedName qualifiedTableName = QualifiedName.of("PUBLIC", "MY_TABLE"); + + // Access a table using the qualified name (includes schema) + Table myTable = tableApi.table(qualifiedTableName); + + Tuple personTuple = Tuple.create() + .set("id", 1) + .set("cityId", "3") + .set("name", "John") + .set("age", 32) + .set("company", ""); Review Comment: I suggest to fill it up with `Apache` as example, not just empty value, to check it in queries. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org