KDB: how do I do bulk insert in Java?












0















I have a table with String columns "key1", "col1", "col2", "col3". I have a snippet below to test the bulk insert. When I run it, I don't get any error, yet I don't see any changes to the "test" table.



Did I miss something?



        Object data = new Object[4];

ArrayList<String> rec = new ArrayList[4];

rec[0] = new ArrayList<String>();
rec[1] = new ArrayList<String>();
rec[2] = new ArrayList<String>();
rec[3] = new ArrayList<String>();

for (Integer i = 0; i < 10; i++) {

rec[0].add(i.toString() + i.toString() + i.toString());
rec[1].add(i.toString() + i.toString() + i.toString());
rec[2].add(i.toString() + i.toString() + i.toString());
rec[3].add(i.toString() + i.toString() + i.toString());

}

for (int i = 0; i < 4; i++) {
data[i] = rec[i].toArray(new Object[rec[i].size()]);
}

c.Dict dict = new c.Dict(Arrays.asList("key1", "col1", "col2", "col3").toArray(new String[4]), data);
c.Flip flip = new c.Flip(dict);

Object updStatement = new Object { ".u.upd", "test", flip };

conn.ks(updStatement);









share|improve this question























  • create a local q session, put the same test schema there, update the operation from .u.upd to insert and test it. you will see the error on the console if anything is wrong with the schema or the data you are sending.

    – aliak
    Nov 27 '18 at 23:30











  • there was an error. it says 'insert

    – user3682563
    Nov 28 '18 at 14:17











  • Apparently this does not work for me: Object updStatement = new Object { "insert", "test", flip }; conn.ks(updStatement);. What worked is this: conn.ks("insert", "test", flip);

    – user3682563
    Nov 28 '18 at 14:37


















0















I have a table with String columns "key1", "col1", "col2", "col3". I have a snippet below to test the bulk insert. When I run it, I don't get any error, yet I don't see any changes to the "test" table.



Did I miss something?



        Object data = new Object[4];

ArrayList<String> rec = new ArrayList[4];

rec[0] = new ArrayList<String>();
rec[1] = new ArrayList<String>();
rec[2] = new ArrayList<String>();
rec[3] = new ArrayList<String>();

for (Integer i = 0; i < 10; i++) {

rec[0].add(i.toString() + i.toString() + i.toString());
rec[1].add(i.toString() + i.toString() + i.toString());
rec[2].add(i.toString() + i.toString() + i.toString());
rec[3].add(i.toString() + i.toString() + i.toString());

}

for (int i = 0; i < 4; i++) {
data[i] = rec[i].toArray(new Object[rec[i].size()]);
}

c.Dict dict = new c.Dict(Arrays.asList("key1", "col1", "col2", "col3").toArray(new String[4]), data);
c.Flip flip = new c.Flip(dict);

Object updStatement = new Object { ".u.upd", "test", flip };

conn.ks(updStatement);









share|improve this question























  • create a local q session, put the same test schema there, update the operation from .u.upd to insert and test it. you will see the error on the console if anything is wrong with the schema or the data you are sending.

    – aliak
    Nov 27 '18 at 23:30











  • there was an error. it says 'insert

    – user3682563
    Nov 28 '18 at 14:17











  • Apparently this does not work for me: Object updStatement = new Object { "insert", "test", flip }; conn.ks(updStatement);. What worked is this: conn.ks("insert", "test", flip);

    – user3682563
    Nov 28 '18 at 14:37
















0












0








0








I have a table with String columns "key1", "col1", "col2", "col3". I have a snippet below to test the bulk insert. When I run it, I don't get any error, yet I don't see any changes to the "test" table.



Did I miss something?



        Object data = new Object[4];

ArrayList<String> rec = new ArrayList[4];

rec[0] = new ArrayList<String>();
rec[1] = new ArrayList<String>();
rec[2] = new ArrayList<String>();
rec[3] = new ArrayList<String>();

for (Integer i = 0; i < 10; i++) {

rec[0].add(i.toString() + i.toString() + i.toString());
rec[1].add(i.toString() + i.toString() + i.toString());
rec[2].add(i.toString() + i.toString() + i.toString());
rec[3].add(i.toString() + i.toString() + i.toString());

}

for (int i = 0; i < 4; i++) {
data[i] = rec[i].toArray(new Object[rec[i].size()]);
}

c.Dict dict = new c.Dict(Arrays.asList("key1", "col1", "col2", "col3").toArray(new String[4]), data);
c.Flip flip = new c.Flip(dict);

Object updStatement = new Object { ".u.upd", "test", flip };

conn.ks(updStatement);









share|improve this question














I have a table with String columns "key1", "col1", "col2", "col3". I have a snippet below to test the bulk insert. When I run it, I don't get any error, yet I don't see any changes to the "test" table.



Did I miss something?



        Object data = new Object[4];

ArrayList<String> rec = new ArrayList[4];

rec[0] = new ArrayList<String>();
rec[1] = new ArrayList<String>();
rec[2] = new ArrayList<String>();
rec[3] = new ArrayList<String>();

for (Integer i = 0; i < 10; i++) {

rec[0].add(i.toString() + i.toString() + i.toString());
rec[1].add(i.toString() + i.toString() + i.toString());
rec[2].add(i.toString() + i.toString() + i.toString());
rec[3].add(i.toString() + i.toString() + i.toString());

}

for (int i = 0; i < 4; i++) {
data[i] = rec[i].toArray(new Object[rec[i].size()]);
}

c.Dict dict = new c.Dict(Arrays.asList("key1", "col1", "col2", "col3").toArray(new String[4]), data);
c.Flip flip = new c.Flip(dict);

Object updStatement = new Object { ".u.upd", "test", flip };

conn.ks(updStatement);






kdb






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 27 '18 at 22:00









user3682563user3682563

936




936













  • create a local q session, put the same test schema there, update the operation from .u.upd to insert and test it. you will see the error on the console if anything is wrong with the schema or the data you are sending.

    – aliak
    Nov 27 '18 at 23:30











  • there was an error. it says 'insert

    – user3682563
    Nov 28 '18 at 14:17











  • Apparently this does not work for me: Object updStatement = new Object { "insert", "test", flip }; conn.ks(updStatement);. What worked is this: conn.ks("insert", "test", flip);

    – user3682563
    Nov 28 '18 at 14:37





















  • create a local q session, put the same test schema there, update the operation from .u.upd to insert and test it. you will see the error on the console if anything is wrong with the schema or the data you are sending.

    – aliak
    Nov 27 '18 at 23:30











  • there was an error. it says 'insert

    – user3682563
    Nov 28 '18 at 14:17











  • Apparently this does not work for me: Object updStatement = new Object { "insert", "test", flip }; conn.ks(updStatement);. What worked is this: conn.ks("insert", "test", flip);

    – user3682563
    Nov 28 '18 at 14:37



















create a local q session, put the same test schema there, update the operation from .u.upd to insert and test it. you will see the error on the console if anything is wrong with the schema or the data you are sending.

– aliak
Nov 27 '18 at 23:30





create a local q session, put the same test schema there, update the operation from .u.upd to insert and test it. you will see the error on the console if anything is wrong with the schema or the data you are sending.

– aliak
Nov 27 '18 at 23:30













there was an error. it says 'insert

– user3682563
Nov 28 '18 at 14:17





there was an error. it says 'insert

– user3682563
Nov 28 '18 at 14:17













Apparently this does not work for me: Object updStatement = new Object { "insert", "test", flip }; conn.ks(updStatement);. What worked is this: conn.ks("insert", "test", flip);

– user3682563
Nov 28 '18 at 14:37







Apparently this does not work for me: Object updStatement = new Object { "insert", "test", flip }; conn.ks(updStatement);. What worked is this: conn.ks("insert", "test", flip);

– user3682563
Nov 28 '18 at 14:37














1 Answer
1






active

oldest

votes


















2














Adding onto what you said, you want to be using the ks() method with 2 arguments.



From the javadoc given in the c.java class:




Use this to
* invoke a function in kdb+ which takes 2 arguments and does not return a value. e.g. to invoke f[x;y] use ks("f",x,y);
* to invoke a lambda, use ks("{x+y}",x,y);




The function .u.upd takes in 2 arguments and, by default, has the same signature as insert:




  • First argument is a symbol for the table name, which has the type String in Java

  • Second argument is the records which has the type Object in Java


The length of the Object in the second argument should be equal to the number of columns. Each Object in the Object should itself be an array that has a length equal to the number of records. The order of the inner arrays should be the same order as the columns, and the values of each inner array should have the matching type to the column type in kdb and have the same order as the records.



Your Object should look like:



new Object{
new Object{row1col1, row2col1, /*..., */ rowNcol1},
new Object{row1col2, row2col2, /*..., */ rowNcol2},
/* column 3 to column N-1 values */
new Object{row1colN, row2colN, /*..., */ rowNcolN}
}


And your ks() method call should look like:



conn.ks(".u.upd", "test", new Object{ /*.... */});





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53508870%2fkdb-how-do-i-do-bulk-insert-in-java%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Adding onto what you said, you want to be using the ks() method with 2 arguments.



    From the javadoc given in the c.java class:




    Use this to
    * invoke a function in kdb+ which takes 2 arguments and does not return a value. e.g. to invoke f[x;y] use ks("f",x,y);
    * to invoke a lambda, use ks("{x+y}",x,y);




    The function .u.upd takes in 2 arguments and, by default, has the same signature as insert:




    • First argument is a symbol for the table name, which has the type String in Java

    • Second argument is the records which has the type Object in Java


    The length of the Object in the second argument should be equal to the number of columns. Each Object in the Object should itself be an array that has a length equal to the number of records. The order of the inner arrays should be the same order as the columns, and the values of each inner array should have the matching type to the column type in kdb and have the same order as the records.



    Your Object should look like:



    new Object{
    new Object{row1col1, row2col1, /*..., */ rowNcol1},
    new Object{row1col2, row2col2, /*..., */ rowNcol2},
    /* column 3 to column N-1 values */
    new Object{row1colN, row2colN, /*..., */ rowNcolN}
    }


    And your ks() method call should look like:



    conn.ks(".u.upd", "test", new Object{ /*.... */});





    share|improve this answer






























      2














      Adding onto what you said, you want to be using the ks() method with 2 arguments.



      From the javadoc given in the c.java class:




      Use this to
      * invoke a function in kdb+ which takes 2 arguments and does not return a value. e.g. to invoke f[x;y] use ks("f",x,y);
      * to invoke a lambda, use ks("{x+y}",x,y);




      The function .u.upd takes in 2 arguments and, by default, has the same signature as insert:




      • First argument is a symbol for the table name, which has the type String in Java

      • Second argument is the records which has the type Object in Java


      The length of the Object in the second argument should be equal to the number of columns. Each Object in the Object should itself be an array that has a length equal to the number of records. The order of the inner arrays should be the same order as the columns, and the values of each inner array should have the matching type to the column type in kdb and have the same order as the records.



      Your Object should look like:



      new Object{
      new Object{row1col1, row2col1, /*..., */ rowNcol1},
      new Object{row1col2, row2col2, /*..., */ rowNcol2},
      /* column 3 to column N-1 values */
      new Object{row1colN, row2colN, /*..., */ rowNcolN}
      }


      And your ks() method call should look like:



      conn.ks(".u.upd", "test", new Object{ /*.... */});





      share|improve this answer




























        2












        2








        2







        Adding onto what you said, you want to be using the ks() method with 2 arguments.



        From the javadoc given in the c.java class:




        Use this to
        * invoke a function in kdb+ which takes 2 arguments and does not return a value. e.g. to invoke f[x;y] use ks("f",x,y);
        * to invoke a lambda, use ks("{x+y}",x,y);




        The function .u.upd takes in 2 arguments and, by default, has the same signature as insert:




        • First argument is a symbol for the table name, which has the type String in Java

        • Second argument is the records which has the type Object in Java


        The length of the Object in the second argument should be equal to the number of columns. Each Object in the Object should itself be an array that has a length equal to the number of records. The order of the inner arrays should be the same order as the columns, and the values of each inner array should have the matching type to the column type in kdb and have the same order as the records.



        Your Object should look like:



        new Object{
        new Object{row1col1, row2col1, /*..., */ rowNcol1},
        new Object{row1col2, row2col2, /*..., */ rowNcol2},
        /* column 3 to column N-1 values */
        new Object{row1colN, row2colN, /*..., */ rowNcolN}
        }


        And your ks() method call should look like:



        conn.ks(".u.upd", "test", new Object{ /*.... */});





        share|improve this answer















        Adding onto what you said, you want to be using the ks() method with 2 arguments.



        From the javadoc given in the c.java class:




        Use this to
        * invoke a function in kdb+ which takes 2 arguments and does not return a value. e.g. to invoke f[x;y] use ks("f",x,y);
        * to invoke a lambda, use ks("{x+y}",x,y);




        The function .u.upd takes in 2 arguments and, by default, has the same signature as insert:




        • First argument is a symbol for the table name, which has the type String in Java

        • Second argument is the records which has the type Object in Java


        The length of the Object in the second argument should be equal to the number of columns. Each Object in the Object should itself be an array that has a length equal to the number of records. The order of the inner arrays should be the same order as the columns, and the values of each inner array should have the matching type to the column type in kdb and have the same order as the records.



        Your Object should look like:



        new Object{
        new Object{row1col1, row2col1, /*..., */ rowNcol1},
        new Object{row1col2, row2col2, /*..., */ rowNcol2},
        /* column 3 to column N-1 values */
        new Object{row1colN, row2colN, /*..., */ rowNcolN}
        }


        And your ks() method call should look like:



        conn.ks(".u.upd", "test", new Object{ /*.... */});






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 29 '18 at 12:01

























        answered Nov 28 '18 at 17:49









        Tin-PuiTin-Pui

        712




        712
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53508870%2fkdb-how-do-i-do-bulk-insert-in-java%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)