Maksim Zhuravkov created IGNITE-27739:
-----------------------------------------
Summary: Thin client. KeyValueView ignores decimal precision
Key: IGNITE-27739
URL: https://issues.apache.org/jira/browse/IGNITE-27739
Project: Ignite
Issue Type: Bug
Components: thin clients ai3
Affects Versions: 3.1
Reporter: Maksim Zhuravkov
Client's KeyValueView ignores precision specified in a column definition and
allows into insert values with larger precision than it is allowed by column's
type
{noformat}
import java.math.BigDecimal;
import java.util.Map;
import org.apache.ignite.Ignite;
import org.apache.ignite.client.IgniteClient;
import org.apache.ignite.internal.ClusterPerClassIntegrationTest;
import org.apache.ignite.sql.IgniteSql;
import org.apache.ignite.table.KeyValueView;
import org.apache.ignite.table.Table;
import org.apache.ignite.table.Tuple;
import org.apache.ignite.tx.Transaction;
import org.junit.jupiter.api.Test;
public class BigDecimalExample extends ClusterPerClassIntegrationTest {
@Test
public void client() {
try (IgniteClient client =
IgniteClient.builder().addresses("localhost:10800").build()) {
example(client);
}
}
@Test
public void embedded() {
Ignite node = node(0);
example(node);
}
private static void example(Ignite ignite) {
IgniteSql sql = ignite.sql();
sql.executeScript("" +
"DROP TABLE IF EXISTS kv1;" +
"CREATE TABLE kv1 (key INT, val DECIMAL(10,2), PRIMARY KEY
(key) );" +
"DROP TABLE IF EXISTS kv2;" +
"CREATE TABLE kv2 (key INT, str VARCHAR(10), val DECIMAL(10,2),
PRIMARY KEY (key) )"
);
execute(ignite, "kv1");
System.err.println("----");
execute(ignite, "kv2");
}
private static void execute(Ignite client, String tableName) {
Table table = client.tables().table(tableName);
KeyValueView<Tuple, Tuple> view = table.keyValueView();
Tuple key = Tuple.create(Map.of("key", 1));
Tuple value = Tuple.create(Map.of("val", new
BigDecimal("11223344556677889900.123456")));
try {
view.put(null, key, value);
System.err.println("KV OK>" + view.get(null, key));
} catch (Exception e) {
System.err.println("KV ERROR>" + e);
}
IgniteSql sql = client.sql();
try {
try (var rs = sql.execute((Transaction) null,
"INSERT INTO " + tableName + "(key, val) VALUES(2,
11223344556677889900.123456)")) {
System.err.println("SQL OK>" + rs.affectedRows());
}
} catch (Exception e) {
System.err.println("SQL ERROR>" + e);
}
}
}
{noformat}
Output for client:
{noformat}
KV OK>ClientTuple [VAL=11223344556677889900.12]
SQL ERROR>org.apache.ignite.sql.SqlException: IGN-SQL-7 Numeric field overflow.
A field with precision 10, scale 2 must round to an absolute value less than
10^8. TraceId:496ec5d5
----
KV ERROR>org.apache.ignite.lang.MarshallerException: IGN-MARSHALLING-1 Failed
to serialize row for table PUBLIC.KV2. Numeric field overflow in column 'VAL'
TraceId:d90ffb3f
SQL ERROR>org.apache.ignite.sql.SqlException: IGN-SQL-7 Numeric field overflow.
A field with precision 10, scale 2 must round to an absolute value less than
10^8. TraceId:68bf21f2
{noformat}
Output for embedded:
{noformat}
KV ERROR>org.apache.ignite.lang.MarshallerException: IGN-MARSHALLING-1 Failed
to serialize row for table PUBLIC.KV1. Numeric field overflow in column 'VAL'
TraceId:543d0392
SQL ERROR>org.apache.ignite.sql.SqlException: IGN-SQL-7 Numeric field overflow.
A field with precision 10, scale 2 must round to an absolute value less than
10^8. TraceId:53cab003
----
KV ERROR>org.apache.ignite.lang.MarshallerException: IGN-MARSHALLING-1 Failed
to serialize row for table PUBLIC.KV2. Numeric field overflow in column 'VAL'
TraceId:2b2b486e
SQL ERROR>org.apache.ignite.sql.SqlException: IGN-SQL-7 Numeric field overflow.
A field with precision 10, scale 2 must round to an absolute value less than
10^8. TraceId:b83a8cb2
{noformat}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)