1

I am trying to create a table with array data type in apache ignite using following query.

create table test(id int,word varchar,vector array,primary key(id));

with this above query i am able to create a table test. 0

: jdbc:ignite:thin://127.0.0.1/> !tables
+--------------------------------+--------------------------------+--------------------------------+--------------------------------+----------------+
|           TABLE_CAT            |          TABLE_SCHEM           |           TABLE_NAME           |           TABLE_TYPE           |            REM |
+--------------------------------+--------------------------------+--------------------------------+--------------------------------+----------------+
|                                | wordVectorCache                | WORDTOVECTORBASICDETAILS       | TABLE                          |                |
|                             | PUBLIC                         | TEST                           | TABLE                          |                |
+--------------------------------+--------------------------------+--------------------------------+--------------------------------+----------------+

if i tried same with following query

create table test1(id int,word varchar,vector char[],primary key(id));

i got following error,

0: jdbc:ignite:thin://127.0.0.1/> create table test2(id int,word varchar,vector char[],primary key(id));
Error: Failed to parse query. Syntax error in SQL statement "CREATE TABLE TEST2(ID INT,WORD VARCHAR,VECTOR CHAR[[*]],PRIMARY KEY(ID)) "; expected "(, FOR, UNSIGNED, INVISIBLE, VISIBLE, NOT, NULL, AS, DEFAULT, GENERATED, ON, NOT, NULL, AUTO_INCREMENT, BIGSERIAL, SERIAL, IDENTITY, NULL_TO_DEFAULT, SEQUENCE, SELECTIVITY, COMMENT, CONSTRAINT, PRIMARY, UNIQUE, NOT, NULL, CHECK, REFERENCES, ,, )"; SQL statement:
create table test2(id int,word varchar,vector char[],primary key(id)) [42001-197] (state=42000,code=1001)
java.sql.SQLException: Failed to parse query. Syntax error in SQL statement "CREATE TABLE TEST2(ID INT,WORD VARCHAR,VECTOR CHAR[[*]],PRIMARY KEY(ID)) "; expected "(, FOR, UNSIGNED, INVISIBLE, VISIBLE, NOT, NULL, AS, DEFAULT, GENERATED, ON, NOT, NULL, AUTO_INCREMENT, BIGSERIAL, SERIAL, IDENTITY, NULL_TO_DEFAULT, SEQUENCE, SELECTIVITY, COMMENT, CONSTRAINT, PRIMARY, UNIQUE, NOT, NULL, CHECK, REFERENCES, ,, )"; SQL statement:
create table test2(id int,word varchar,vector char[],primary key(id)) [42001-197]
    at org.apache.ignite.internal.jdbc.thin.JdbcThinConnection.sendRequest(JdbcThinConnection.java:750)
    at org.apache.ignite.internal.jdbc.thin.JdbcThinStatement.execute0(JdbcThinStatement.java:212)
    at org.apache.ignite.internal.jdbc.thin.JdbcThinStatement.execute(JdbcThinStatement.java:475)
    at sqlline.Commands.execute(Commands.java:823)
    at sqlline.Commands.sql(Commands.java:733)
    at sqlline.SqlLine.dispatch(SqlLine.java:795)
    at sqlline.SqlLine.begin(SqlLine.java:668)
    at sqlline.SqlLine.start(SqlLine.java:373)
    at sqlline.SqlLine.main(SqlLine.java:265)

Now i tried to insert data into test table, using following query

insert into test values(1,'ramoji',{'123','234'});

this time i faced an issue:

0: jdbc:ignite:thin://127.0.0.1/> insert into test values(1,'ramoji',{'123','234'});
Error: Failed to parse query. Syntax error in SQL statement "insert into test values(1,'ramoji',{'123','234'})[*]" [42000-197] (state=42000,code=1001)
java.sql.SQLException: Failed to parse query. Syntax error in SQL statement "insert into test values(1,'ramoji',{'123','234'})[*]" [42000-197]
    at org.apache.ignite.internal.jdbc.thin.JdbcThinConnection.sendRequest(JdbcThinConnection.java:750)
    at org.apache.ignite.internal.jdbc.thin.JdbcThinStatement.execute0(JdbcThinStatement.java:212)
    at org.apache.ignite.internal.jdbc.thin.JdbcThinStatement.execute(JdbcThinStatement.java:475)
    at sqlline.Commands.execute(Commands.java:823)
    at sqlline.Commands.sql(Commands.java:733)
    at sqlline.SqlLine.dispatch(SqlLine.java:795)
    at sqlline.SqlLine.begin(SqlLine.java:668)
    at sqlline.SqlLine.start(SqlLine.java:373)
    at sqlline.SqlLine.main(SqlLine.java:265)

Can any one please help me how should i use array data type in apache ignite & how to insert data with proper example.

Thank you very much for your help & Support in advance. I will be keep looking for your answers, Please help .....

My sample data for one record is:

insert into text values( 
1,'in',"['0.070312', '0.086914', '0.087891', '0.062500', '0.069336', '-0.108887', '-0.081543', '-0.154297', '0.020752', '0.131836', '-0.113770', '-0.037354', '0.069336', '0.078125', '-0.103027', '-0.097656', '0.044189', '0.102539', '-0.060791', '-0.036133', '-0.045410', '0.047363', '-0.120605', '-0.063965', '0.002258', '0.037109', '-0.002914', '0.117676', '0.061768', '0.063965', '0.081055', '-0.068848', '-0.021362', '0.055176', '-0.085449', '0.068848', '-0.127930', '-0.033203', '0.098633', '0.175781', '0.110840', '-0.034668', '-0.047119', '-0.008484', '0.035889', '0.103027', '0.026978', '-0.028687', '-0.005127', '0.106445', '0.059814', '0.094238', '0.033691', '-0.027100', '-0.094238', '0.001030', '-0.048340', '0.034424', '0.081055', '-0.113281', '-0.088867', '0.035889', '-0.145508', '-0.244141', '-0.061523', '0.052979', '0.056885', '0.179688', '0.061035', '0.086914', '0.124023', '-0.040283', '0.022583', '0.177734', '-0.029663', '-0.029663', '0.117188', '0.031128', '-0.096191', '0.066406', '0.004700', '-0.080078', '0.062988', '-0.020630', '-0.054688', '-0.135742', '-0.063477', '0.083496', '-0.063965', '0.021484', '0.077148', '-0.037109', '-0.033691', '-0.183594', '-0.072754', '0.015869', '0.093262', '-0.061523', '-0.014221', '-0.003448', '0.011108', '-0.158203', '-0.017090', '0.006195', '-0.008728', '-0.080566', '-0.015259', '-0.087891', '0.003479', '-0.016113', '-0.012329', '0.097656', '-0.139648', '-0.085938', '-0.026855', '0.053955', '0.132812', '0.112793', '0.121094', '0.085449', '-0.007111', '0.044678', '-0.145508', '-0.003204', '-0.117676', '-0.065430', '0.071289', '-0.094238', '-0.030273', '0.120117', '0.080078', '-0.094727', '-0.162109', '-0.077637', '0.021240', '-0.081543', '0.003937', '-0.157227', '-0.098145', '0.039795', '0.039307', '-0.009094', '0.103027', '0.067871', '-0.042725', '0.063477', '-0.049072', '0.020874', '-0.166992', '0.093262', '0.093750', '0.006866', '0.053711', '0.052490', '-0.024414', '-0.032471', '-0.061523', '-0.005554', '0.096191', '0.037842', '0.012207', '-0.043945', '-0.007477', '0.105469', '0.020386', '0.145508', '0.082031', '0.005768', '0.004578', '-0.092773', '-0.138672', '-0.057373', '-0.051514', '-0.130859', '-0.139648', '-0.020508', '-0.027100', '0.032715', '0.104980', '-0.002335', '-0.022583', '0.000504', '-0.110840', '0.084961', '-0.129883', '-0.017456', '-0.000359', '0.107910', '0.088867', '0.044678', '0.025146', '0.023804', '0.081055', '0.023682', '-0.109863', '0.005371', '-0.017700', '-0.033936', '-0.032959', '-0.164062', '0.095703', '-0.018311', '0.005310', '-0.034424', '-0.044189', '-0.066406', '-0.017944', '-0.029663', '-0.007599', '-0.051270', '-0.054199', '0.089355', '-0.071777', '0.015259', '-0.082520', '-0.031738', '0.035645', '-0.021240', '-0.059326', '-0.013062', '0.046875', '0.023071', '0.020996', '-0.078613', '-0.008057', '0.019531', '-0.005554', '0.041504', '0.027832', '0.013611', '0.034668', '-0.182617', '0.120117', '0.074219', '-0.041016', '-0.009949', '0.042969', '-0.007294', '0.123047', '0.057617', '-0.053467', '-0.032227', '-0.009094', '-0.046631', '0.043945', '-0.050781', '0.068848', '0.002991', '-0.004181', '-0.044189', '0.073730', '-0.012756', '0.067383', '0.006287', '0.075195', '-0.037842', '0.004883', '0.044678', '-0.067383', '0.009705', '0.004730', '0.020508', '0.071289', '0.170898', '0.173828', '0.055664', '0.091309', '-0.037354', '0.049805', '-0.039307', '0.044189', '0.062500', '0.048584', '-0.053223', '0.048828', '-0.130859', '-0.028931', '-0.036133', '-0.060791', '-0.057373', '0.123047', '-0.082520', '-0.011902', '0.125000', '0.001358', '0.063965', '-0.106445', '-0.143555', '-0.042236', '0.024048', '-0.168945', '-0.088867', '-0.080566', '0.064941', '0.061279', '-0.047363', '-0.058838', '-0.047607', '0.014465', '-0.062500']");

How do i insert this much big data for my third column which should be of type Array.

alamar
  • 18,729
  • 4
  • 64
  • 97

1 Answers1

1

Apache Ignite's SQL does not have syntax for reading or writing arrays. You can store arrays in text form if you like (for example, you can store JSON snippets in VARCHAR columns), or you can store arrays as fields in POJO objects using Ignite's Java APIs (they will not be accessible as SQL table columns in this case).

You can create an ARRAY column, but there is no way to populate it with array literal currently.

alamar
  • 18,729
  • 4
  • 64
  • 97