Search in sources :

Example 6 with Schema

use of com.mysql.cj.xdevapi.Schema in project aws-mysql-jdbc by awslabs.

the class CollectionTest method testArrayIndex011.

@Test
public void testArrayIndex011() throws Exception {
    assumeTrue(mysqlVersionMeetsMinimum(this.baseUrl, ServerVersion.parseVersion("8.0.17")), "MySQL 8.0.17+ is required to run this test.");
    String collname = "coll1";
    Session sess = null;
    try {
        sess = new SessionFactory().getSession(this.baseUrl);
        Schema sch = sess.getDefaultSchema();
        sch.dropCollection(collname);
        Collection coll = sch.createCollection(collname, true);
        /* create basic index */
        coll.createIndex("intArrayIndex", "{\"fields\": [{\"field\": \"$.intField\", \"type\": \"SIGNED INTEGER\", \"array\": true}]}");
        coll.createIndex("uintArrayIndex", "{\"fields\": [{\"field\": \"$.uintField\", \"type\": \"UNSIGNED INTEGER\", \"array\": true}]}");
        coll.createIndex("floatArrayIndex", "{\"fields\": [{\"field\": \"$.floatField\", \"type\": \"DECIMAL(10,2)\", \"array\": true}]}");
        coll.createIndex("dateArrayIndex", "{\"fields\": [{\"field\": \"$.dateField\", \"type\": \"DATE\", \"array\": true}]}");
        coll.createIndex("datetimeArrayIndex", "{\"fields\": [{\"field\": \"$.datetimeField\", \"type\": \"DATETIME\", \"array\": true}]}");
        coll.createIndex("timeArrayIndex", "{\"fields\": [{\"field\": \"$.timeField\", \"type\": \"TIME\", \"array\": true}]}");
        coll.createIndex("charArrayIndex", "{\"fields\": [{\"field\": \"$.charField\", \"type\": \"CHAR(256)\", \"array\": true}]}");
        coll.createIndex("binaryArrayIndex", "{\"fields\": [{\"field\": \"$.binaryField\", \"type\": \"BINARY(256)\", \"array\": true}]}");
        validateArrayIndex("intArrayIndex", "coll1", 1);
        validateArrayIndex("uintArrayIndex", "coll1", 1);
        validateArrayIndex("floatArrayIndex", "coll1", 1);
        validateArrayIndex("dateArrayIndex", "coll1", 1);
        validateArrayIndex("datetimeArrayIndex", "coll1", 1);
        validateArrayIndex("timeArrayIndex", "coll1", 1);
        validateArrayIndex("charArrayIndex", "coll1", 1);
        validateArrayIndex("binaryArrayIndex", "coll1", 1);
        coll.add("{\"intField\" : [], \"uintField\" : [], \"dateField\" : [], \"datetimeField\" : [], \"charField\" : [], \"binaryField\" : [],\"timeField\" : [], \"floatField\" : []}").execute();
        coll.add("{\"intField\" : [], \"uintField\" : [51,52,53], \"dateField\" : [\"2019-1-1\", \"2019-2-1\", \"2019-3-1\"], \"datetimeField\" : [\"9999-12-30 23:59:59\", \"9999-12-29 23:59:59\", \"9999-12-31 23:59:59\"], \"charField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"binaryField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"timeField\" : [\"10.30\", \"11.30\", \"12.30\"], \"floatField\" : [51.1,52.9,53.0]}").execute();
        coll.add("{\"intField\" : [12,23,34], \"uintField\" : [], \"dateField\" : [\"2019-1-1\", \"2019-2-1\", \"2019-3-1\"], \"datetimeField\" : [\"9999-12-31 23:59:59\", \"9999-12-31 23:59:59\", \"9999-12-7 23:59:59\"], \"charField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"binaryField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"timeField\" : [\"10.30\", \"11.30\", \"12.30\"], \"floatField\" : [51.2,52.7,53.6]}").execute();
        coll.add("{\"intField\" : [12,23,34], \"uintField\" : [51,52,53], \"dateField\" : [], \"datetimeField\" : [\"9999-12-31 23:59:59\", \"9999-12-31 23:59:59\", \"9999-12-7 23:59:59\"], \"charField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"binaryField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"timeField\" : [\"10.30\", \"11.30\", \"12.30\"], \"floatField\" : [51.2,52.7,53.6]}").execute();
        coll.add("{\"intField\" : [12,23,34], \"uintField\" : [51,52,53], \"dateField\" : [\"2019-1-1\", \"2019-2-1\", \"2019-3-1\"], \"datetimeField\" : [], \"charField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"binaryField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"timeField\" : [\"10.30\", \"11.30\", \"12.30\"], \"floatField\" : [51.2,52.7,53.6]}").execute();
        coll.add("{\"intField\" : [12,23,34], \"uintField\" : [51,52,53], \"dateField\" : [\"2019-1-1\", \"2019-2-1\", \"2019-3-1\"], \"datetimeField\" : [\"9999-12-31 23:59:59\", \"9999-12-31 23:59:59\", \"9999-12-7 23:59:59\"], \"charField\" : [], \"binaryField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"timeField\" : [\"10.30\", \"11.30\", \"12.30\"], \"floatField\" : [51.2,52.7,53.6]}").execute();
        coll.add("{\"intField\" : [12,23,34], \"uintField\" : [51,52,53], \"dateField\" : [\"2019-1-1\", \"2019-2-1\", \"2019-3-1\"], \"datetimeField\" : [\"9999-12-31 23:59:59\", \"9999-12-31 23:59:59\", \"9999-12-7 23:59:59\"], \"charField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"binaryField\" : [], \"timeField\" : [\"10.30\", \"11.30\", \"12.30\"], \"floatField\" : [51.2,52.7,53.6]}").execute();
        coll.add("{\"intField\" : [12,23,34], \"uintField\" : [51,52,53], \"dateField\" : [\"2019-1-1\", \"2019-2-1\", \"2019-3-1\"], \"datetimeField\" : [\"9999-12-31 23:59:59\", \"9999-12-31 23:59:59\", \"9999-12-7 23:59:59\"], \"charField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"binaryField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"timeField\" : [], \"floatField\" : [51.2,52.7,53.6]}").execute();
        coll.add("{\"intField\" : [12,23,34], \"uintField\" : [51,52,53], \"dateField\" : [\"2019-1-1\", \"2019-2-1\", \"2019-3-1\"], \"datetimeField\" : [\"9999-12-31 23:59:59\", \"9999-12-31 23:59:59\", \"9999-12-7 23:59:59\"], \"charField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"binaryField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"timeField\" : [\"10.30\", \"11.30\", \"12.30\"], \"floatField\" : []}").execute();
        try {
            coll.add("{\"intField\" : [1,[2, 3],4], \"uintField\" : [51,[52, 53],54], \"dateField\" : [\"2019-1-1\", [\"2019-2-1\", \"2019-3-1\"], \"2019-4-1\"], \"datetimeField\" : [\"9999-12-30 23:59:59\", [\"9999-12-31 23:59:59\"], \"9999-12-31 23:59:59\"], \"charField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"binaryField\" : [\"abcd1\", [\"abcd1\", \"abcd2\"], \"abcd4\"],\"timeField\" : [\"10.30\", \"11.30\", \"12.30\"], \"floatField\" : [51.2,[52.4],53.6]}").execute();
            assertTrue(false);
        } catch (Exception e) {
            System.out.println("ERROR : " + e.getMessage());
            assertTrue(e.getMessage().contains("Cannot store an array or an object in a scalar key part of the index"));
        }
        try {
            coll.add("{\"intField\" : \"\", \"uintField\" : [51,[52, 53],54], \"dateField\" : [\"2019-1-1\", [\"2019-2-1\", \"2019-3-1\"], \"2019-4-1\"], \"datetimeField\" : [\"9999-12-30 23:59:59\", \"9999-12-31 23:59:59\", \"9999-12-31 23:59:59\"], \"charField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"binaryField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"],\"timeField\" : [\"10.30\", \"11.30\", \"12.30\"], \"floatField\" : [51.2,52.4,53.6]}").execute();
            assertTrue(false);
        } catch (Exception e) {
            System.out.println("ERROR : " + e.getMessage());
            if (mysqlVersionMeetsMinimum(this.baseUrl, ServerVersion.parseVersion("8.0.18"))) {
                assertTrue(e.getMessage().contains("Cannot store an array or an object in a scalar key part of the index"));
            } else {
                assertTrue(e.getMessage().contains("functional index"));
            }
        }
        try {
            coll.add("{\"intField\" : [1,5,4], \"dateField\" : \"\", \"datetimeField\" : \"\", \"charField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"binaryField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"],\"timeField\" : \"\", \"floatField\" : [51.2,52.4,53.6]}").execute();
            assertTrue(false);
        } catch (Exception e) {
            System.out.println("ERROR : " + e.getMessage());
            assertTrue(e.getMessage().contains("functional index"));
        }
        try {
            coll.add("{\"intField\" : [1,5,4], \"dateField\" : [\"2019-1-1\", \"2019-2-1\", \"2019-3-1\", \"2019-4-1\"], \"datetimeField\" : [\"9999-12-30 23:59:59\", \"9999-12-31 23:59:59\", \"9999-12-31 23:59:59\"], \"charField\" : \"\", \"binaryField\" : \"\", \"timeField\" : [\"10.30\", \"11.30\", \"12.30\"], \"floatField\" : [51.2,52.4,53.6]}").execute();
        } catch (Exception e) {
            System.out.println("ERROR : " + e.getMessage());
            assertTrue(e.getMessage().contains("functional index"));
        }
        sch.dropCollection(collname);
    } finally {
        if (sess != null) {
            sess.close();
            sess = null;
        }
    }
}
Also used : SessionFactory(com.mysql.cj.xdevapi.SessionFactory) Schema(com.mysql.cj.xdevapi.Schema) Collection(com.mysql.cj.xdevapi.Collection) JsonString(com.mysql.cj.xdevapi.JsonString) WrongArgumentException(com.mysql.cj.exceptions.WrongArgumentException) ExecutionException(java.util.concurrent.ExecutionException) Session(com.mysql.cj.xdevapi.Session) Test(org.junit.jupiter.api.Test)

Example 7 with Schema

use of com.mysql.cj.xdevapi.Schema in project aws-mysql-jdbc by awslabs.

the class CollectionTest method testArrayIndex010.

@Test
public void testArrayIndex010() throws Exception {
    assumeTrue(mysqlVersionMeetsMinimum(this.baseUrl, ServerVersion.parseVersion("8.0.17")), "MySQL 8.0.17+ is required to run this test.");
    String collname = "coll1";
    Session sess = null;
    try {
        sess = new SessionFactory().getSession(this.baseUrl);
        Schema sch = sess.getDefaultSchema();
        sch.dropCollection(collname);
        Collection coll = sch.createCollection(collname, true);
        try {
            coll.createIndex("multiArrayIndex1", "{\"fields\": [{\"field\": \"$.charField\", \"type\":\"CHAR(128)\", \"array\": true}," + "{\"field\": \"$.binaryField\", \"type\":\"BINARY(128)\"}," + "{\"field\": \"$.intField\", \"type\":\"SIGNED INTEGER\"}," + "{\"field\": \"$.intField2\", \"type\":\"SIGNED\"}," + "{\"field\": \"$.uintField\", \"type\":\"UNSIGNED\"}," + "{\"field\": \"$.uintField2\", \"type\":\"UNSIGNED INTEGER\"}," + "{\"field\": \"$.dateField\", \"type\":\"DATE\"}," + "{\"field\": \"$.datetimeField\", \"type\":\"DATETIME\"}," + "{\"field\": \"$.decimalField\", \"type\":\"DECIMAL(20,9)\"}" + "]}");
        } catch (Exception e) {
            System.out.println("ERROR : " + e.getMessage());
            assertTrue(e.getMessage().contains("Invalid or unsupported type specification 'BINARY(128)'"));
        }
        coll.add("{\"intField\" : 1, \"dateField\" : \"2019-3-1\", \"charField\" : \"abcd1\", \"timeField\" : [\"10.30\", \"11.30\", \"12.30\"]}").execute();
        coll.add("{\"intField\" : 2, \"dateField\" : \"2019-5-1\", \"charField\" : \"abcd2\", \"timeField\" : [\"10.30\", \"11.30\", \"12.30\"]}").execute();
        coll.add("{\"intField\" : 3, \"dateField\" : \"2019-7-1\", \"charField\" : \"abcd3\", \"timeField\" : [\"10.30\", \"11.30\", \"12.30\"]}").execute();
        sch.dropCollection(collname);
    } finally {
        if (sess != null) {
            sess.close();
            sess = null;
        }
    }
}
Also used : SessionFactory(com.mysql.cj.xdevapi.SessionFactory) Schema(com.mysql.cj.xdevapi.Schema) Collection(com.mysql.cj.xdevapi.Collection) JsonString(com.mysql.cj.xdevapi.JsonString) WrongArgumentException(com.mysql.cj.exceptions.WrongArgumentException) ExecutionException(java.util.concurrent.ExecutionException) Session(com.mysql.cj.xdevapi.Session) Test(org.junit.jupiter.api.Test)

Example 8 with Schema

use of com.mysql.cj.xdevapi.Schema in project aws-mysql-jdbc by awslabs.

the class CollectionTest method testArrayIndex009.

@Test
public void testArrayIndex009() throws Exception {
    assumeTrue(mysqlVersionMeetsMinimum(this.baseUrl, ServerVersion.parseVersion("8.0.17")), "MySQL 8.0.17+ is required to run this test.");
    String collname = "coll1";
    Session sess = null;
    try {
        sess = new SessionFactory().getSession(this.baseUrl);
        Schema sch = sess.getDefaultSchema();
        sch.dropCollection(collname);
        Collection coll = sch.createCollection(collname, true);
        /* create basic index */
        coll.createIndex("intArrayIndex", "{\"fields\": [{\"field\": \"$.intField\", \"type\": \"UNSIGNED\", \"array\" : true}], \"type\" : \"INDEX\"}");
        coll.createIndex("dateArrayIndex", "{\"fields\": [{\"field\": \"$.dateField\", \"type\": \"DATE\", \"array\" : true}], \"type\" : \"INDEX\"}");
        coll.createIndex("charArrayIndex", "{\"fields\": [{\"field\": \"$.charField\", \"type\": \"CHAR(255)\", \"array\" : true}], \"type\" : \"INDEX\"}");
        coll.createIndex("timeArrayIndex", "{\"fields\": [{\"field\": \"$.timeField\", \"type\": \"TIME\", \"array\" : true}], \"type\" : \"INDEX\"}");
        validateArrayIndex("intArrayIndex", "coll1", 1);
        validateArrayIndex("dateArrayIndex", "coll1", 1);
        validateArrayIndex("charArrayIndex", "coll1", 1);
        validateArrayIndex("timeArrayIndex", "coll1", 1);
        coll.add("{\"intField\" : [1,2,3], \"dateField\" : [\"2019-1-1\", \"2019-2-1\", \"2019-3-1\"], \"charField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"timeField\" : [\"10.30\", \"11.30\", \"12.30\"]}").execute();
        coll.add("{\"intField\" : [11,12,3], \"dateField\" : [\"2019-1-1\", \"2019-2-1\", \"2019-3-1\"], \"charField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"timeField\" : [\"10.30\", \"11.30\", \"12.30\"]}").execute();
        coll.add("{\"intField\" : [12,23,34], \"dateField\" : [\"2019-1-1\", \"2019-2-1\", \"2019-3-1\"], \"charField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"timeField\" : [\"10.30\", \"11.30\", \"12.30\"]}").execute();
        coll.add("{\"dateField\" : [\"2019-1-1\", \"2019-2-1\", \"2019-3-1\"], \"charField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"timeField\" : [\"10.30\", \"11.30\", \"12.30\"]}").execute();
        coll.add("{\"intField\" : [1,2,3], \"charField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"timeField\" : [\"10.30\", \"11.30\", \"12.30\"]}").execute();
        coll.add("{\"intField\" : [11,12,3], \"dateField\" : [\"2019-1-1\", \"2019-2-1\", \"2019-3-1\"], \"timeField\" : [\"10.30\", \"11.30\", \"12.30\"]}").execute();
        coll.add("{\"intField\" : [11,12,3], \"dateField\" : [\"2019-1-1\", \"2019-2-1\", \"2019-3-1\"], \"charField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"]}").execute();
        try {
            coll.add("{\"intField\" : \"[12,23,34]\", \"dateField\" : [\"2019-1-1\", \"2019-2-1\", \"2019-3-1\"], \"charField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"timeField\" : [\"10.30\", \"11.30\", \"12.30\"]}").execute();
            assertTrue(false);
        } catch (Exception e) {
            System.out.println("ERROR : " + e.getMessage());
            assertTrue(e.getMessage().contains("functional index"));
        }
        sch.dropCollection(collname);
    } finally {
        if (sess != null) {
            sess.close();
            sess = null;
        }
    }
}
Also used : SessionFactory(com.mysql.cj.xdevapi.SessionFactory) Schema(com.mysql.cj.xdevapi.Schema) Collection(com.mysql.cj.xdevapi.Collection) JsonString(com.mysql.cj.xdevapi.JsonString) WrongArgumentException(com.mysql.cj.exceptions.WrongArgumentException) ExecutionException(java.util.concurrent.ExecutionException) Session(com.mysql.cj.xdevapi.Session) Test(org.junit.jupiter.api.Test)

Example 9 with Schema

use of com.mysql.cj.xdevapi.Schema in project aws-mysql-jdbc by awslabs.

the class CollectionTest method testArrayIndex008.

@Test
public void testArrayIndex008() throws Exception {
    assumeTrue(mysqlVersionMeetsMinimum(this.baseUrl, ServerVersion.parseVersion("8.0.17")), "MySQL 8.0.17+ is required to run this test.");
    String collname = "coll1";
    Session sess = null;
    try {
        sess = new SessionFactory().getSession(this.baseUrl);
        Schema sch = sess.getDefaultSchema();
        sch.dropCollection(collname);
        Collection coll = sch.createCollection(collname, true);
        try {
            coll.createIndex("textArrayIndex", "{\"fields\": [{\"field\": \"$.textField\", \"type\": \"TEXT\", \"array\": true}]}");
            assertTrue(false);
        } catch (Exception e) {
            System.out.println("ERROR : " + e.getMessage());
            assertTrue(e.getMessage().contains("index"));
        }
        try {
            coll.createIndex("boolArrayIndex", "{\"fields\": [{\"field\": \"$.boolField\", \"type\": \"BOOL\", \"array\": true}]}");
            assertTrue(false);
        } catch (Exception e) {
            System.out.println("ERROR : " + e.getMessage());
            assertTrue(e.getMessage().contains("index"));
        }
        try {
            coll.createIndex("blobIndex", "{\"fields\": [{\"field\": \"$.blobField\", \"type\": \"BLOB\", \"array\": true}]}");
            assertTrue(false);
        } catch (Exception e) {
            System.out.println("ERROR : " + e.getMessage());
            assertTrue(e.getMessage().contains("index"));
        }
        try {
            coll.createIndex("sintIndex", "{\"fields\": [{\"field\": \"$.sinField\", \"type\": \"SMALLINT\", \"array\": true}]}");
            assertTrue(false);
        } catch (Exception e) {
            System.out.println("ERROR : " + e.getMessage());
            assertTrue(e.getMessage().contains("index"));
        }
        sch.dropCollection(collname);
    } finally {
        if (sess != null) {
            sess.close();
            sess = null;
        }
    }
}
Also used : SessionFactory(com.mysql.cj.xdevapi.SessionFactory) Schema(com.mysql.cj.xdevapi.Schema) Collection(com.mysql.cj.xdevapi.Collection) JsonString(com.mysql.cj.xdevapi.JsonString) WrongArgumentException(com.mysql.cj.exceptions.WrongArgumentException) ExecutionException(java.util.concurrent.ExecutionException) Session(com.mysql.cj.xdevapi.Session) Test(org.junit.jupiter.api.Test)

Example 10 with Schema

use of com.mysql.cj.xdevapi.Schema in project aws-mysql-jdbc by awslabs.

the class CollectionTest method testArrayIndex014.

@Test
public void testArrayIndex014() throws Exception {
    assumeTrue(mysqlVersionMeetsMinimum(this.baseUrl, ServerVersion.parseVersion("8.0.17")), "MySQL 8.0.17+ is required to run this test.");
    String collname = "coll1";
    DbDoc doc = null;
    Session sess = null;
    try {
        sess = new SessionFactory().getSession(this.baseUrl);
        Schema sch = sess.getDefaultSchema();
        sch.dropCollection(collname);
        Collection coll = sch.createCollection(collname, true);
        /* create basic index */
        coll.createIndex("intArrayIndex", "{\"fields\": [{\"field\": \"$.intField\", \"type\": \"SIGNED INTEGER\", \"array\": true}]}");
        coll.createIndex("uintArrayIndex", "{\"fields\": [{\"field\": \"$.uintField\", \"type\": \"UNSIGNED INTEGER\", \"array\": true}]}");
        coll.createIndex("floatArrayIndex", "{\"fields\": [{\"field\": \"$.floatField\", \"type\": \"DECIMAL(10,2)\", \"array\": true}]}");
        coll.createIndex("dateArrayIndex", "{\"fields\": [{\"field\": \"$.dateField\", \"type\": \"DATE\", \"array\": true}]}");
        coll.createIndex("datetimeArrayIndex", "{\"fields\": [{\"field\": \"$.datetimeField\", \"type\": \"DATETIME\", \"array\": true}]}");
        coll.createIndex("timeArrayIndex", "{\"fields\": [{\"field\": \"$.timeField\", \"type\": \"TIME\", \"array\": true}]}");
        coll.createIndex("charArrayIndex", "{\"fields\": [{\"field\": \"$.charField\", \"type\": \"CHAR(256)\", \"array\": true}]}");
        coll.createIndex("binaryArrayIndex", "{\"fields\": [{\"field\": \"$.binaryField\", \"type\": \"BINARY(256)\", \"array\": true}]}");
        validateArrayIndex("intArrayIndex", "coll1", 1);
        validateArrayIndex("uintArrayIndex", "coll1", 1);
        validateArrayIndex("floatArrayIndex", "coll1", 1);
        validateArrayIndex("dateArrayIndex", "coll1", 1);
        validateArrayIndex("datetimeArrayIndex", "coll1", 1);
        validateArrayIndex("timeArrayIndex", "coll1", 1);
        validateArrayIndex("charArrayIndex", "coll1", 1);
        validateArrayIndex("binaryArrayIndex", "coll1", 1);
        coll.remove("true").execute();
        coll.add("{\"intField\" : [1,2,3], \"uintField\" : [51,52,53], \"dateField\" : [\"2019-1-1\", \"2019-2-1\", \"2019-3-1\"], \"datetimeField\" : [\"9999-12-30 23:59:59\", \"9999-12-31 23:59:59\", \"9999-12-31 23:59:59\"], \"charField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"binaryField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"],\"timeField\" : [\"10.30\", \"11.30\", \"12.30\"], \"floatField\" : [51.2,52.4,53.6],\"dateFieldWOI\" : \"2019-1-1\"}").execute();
        coll.add("{\"intField\" : [11,12,3], \"uintField\" : [51,52,53], \"dateField\" : [\"2019-1-1\", \"2019-2-1\", \"2019-3-1\"], \"datetimeField\" : [\"9999-12-30 23:59:59\", \"9999-12-29 23:59:59\", \"9999-12-31 23:59:59\"], \"charField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"binaryField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"timeField\" : [\"10.30\", \"11.30\", \"12.30\"], \"floatField\" : [51.1,52.9,53.0],\"dateFieldWOI\" : \"2019-1-1\"}").execute();
        coll.add("{\"intField\" : [12,23,34], \"uintField\" : [51,52,53], \"dateField\" : [\"2019-1-1\", \"2019-2-1\", \"2019-3-1\"], \"datetimeField\" : [\"9999-12-31 23:59:59\", \"9999-12-31 23:59:59\", \"9999-12-7 23:59:59\"], \"charField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"binaryField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"timeField\" : [\"10.30\", \"7.30\", \"12.30\"], \"floatField\" : [51.2,52.7,53.6],\"dateFieldWOI\" : \"2019-2-1\"}").execute();
        try {
            coll.add("{\"intField\" : \"[1,2,3]\", \"uintField\" : [51,52,53], \"dateField\" : [\"2019-1-1\", \"2019-2-1\", \"2019-3-1\"], \"datetimeField\" : [\"9999-12-30 23:59:59\", \"9999-12-31 23:59:59\", \"9999-12-31 23:59:59\"], \"charField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"], \"binaryField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"],\"timeField\" : [\"10.30\", \"11.30\", \"12.30\"], \"floatField\" : [51.2,52.4,53.6]}").execute();
            assertTrue(false);
        } catch (Exception e) {
            System.out.println("ERROR : " + e.getMessage());
            assertTrue(e.getMessage().contains("functional index"));
        }
        DocResult docs = coll.find(":intField in $.intField").bind("intField", 12).execute();
        doc = null;
        int i = 0;
        while (docs.hasNext()) {
            doc = docs.next();
            i++;
        }
        assertTrue(i == 2);
        docs = coll.find(":uintField in $.uintField").bind("uintField", 52).execute();
        doc = null;
        i = 0;
        while (docs.hasNext()) {
            doc = docs.next();
            i++;
        }
        assertTrue(i == 3);
        docs = coll.find(":charField in $.charField").bind("charField", "abcd1").execute();
        doc = null;
        i = 0;
        while (docs.hasNext()) {
            doc = docs.next();
            i++;
        }
        assertTrue(i == 3);
        docs = coll.find(":binaryField in $.binaryField").bind("binaryField", "abcd1").execute();
        doc = null;
        i = 0;
        while (docs.hasNext()) {
            doc = docs.next();
            i++;
        }
        assertTrue(i == 3);
        docs = coll.find(":floatField in $.floatField").bind("floatField", 51.2).execute();
        doc = null;
        i = 0;
        while (docs.hasNext()) {
            doc = docs.next();
            i++;
        }
        System.out.println("Count = " + i);
        assertTrue(i == 2);
        docs = coll.find("CAST(CAST('2019-2-1' as DATE) as JSON) in $.dateField").execute();
        doc = null;
        i = 0;
        while (docs.hasNext()) {
            doc = docs.next();
            i++;
        }
        System.out.println("Count = " + i);
        assertTrue(i == 3);
        docs = coll.find("CAST(CAST('2019-2-1' as DATE) as JSON) not in $.dateField").execute();
        doc = null;
        i = 0;
        while (docs.hasNext()) {
            doc = docs.next();
            i++;
        }
        System.out.println("Using NOT IN");
        System.out.println("Count = " + i);
        // assertTrue(i == 0);
        docs = coll.find("'2019-1-1' not in $.dateFieldWOI").execute();
        doc = null;
        i = 0;
        while (docs.hasNext()) {
            doc = docs.next();
            System.out.println((((JsonString) doc.get("dateFieldWOI")).getString()));
            i++;
        }
        System.out.println("Using NOT IN Without Index");
        System.out.println("Count = " + i);
        docs = coll.find("CAST(CAST('2019-2-1' as DATE) as JSON) overlaps $.dateField").execute();
        doc = null;
        i = 0;
        while (docs.hasNext()) {
            doc = docs.next();
            i++;
        }
        System.out.println("Count = " + i);
        assertTrue(i == 3);
        docs = coll.find("CAST(CAST('2019-2-1' as DATE) as JSON) not overlaps $.dateField").execute();
        doc = null;
        i = 0;
        while (docs.hasNext()) {
            doc = docs.next();
            i++;
        }
        System.out.println("Using NOT OVERLAPS");
        System.out.println("Count = " + i);
        // assertTrue(i == 0);
        docs = coll.find("CAST(CAST(:datetimeField as DATETIME) as JSON) in $.datetimeField").bind("datetimeField", "9999-12-30 23:59:59").execute();
        doc = null;
        i = 0;
        while (docs.hasNext()) {
            doc = docs.next();
            i++;
        }
        System.out.println("Count = " + i);
        assertTrue(i == 2);
        docs = coll.find("CAST(CAST(:timeField as TIME) as JSON) in $.timeField").bind("timeField", "7.30").execute();
        doc = null;
        i = 0;
        while (docs.hasNext()) {
            doc = docs.next();
            i++;
        }
        System.out.println("Count = " + i);
        assertTrue(i == 1);
        // Integration scenarios between Index and Overlaps. Explicit casting added due to server Bug#29752056. NOT IN and NOT OVERLAPS doesn't require explicit casting
        docs = coll.find("CAST(CAST('2019-2-1' as DATE) as JSON) in $.dateField").execute();
        // System.out.println("Number of rows using IN with indexed array = "+docs.count());
        assertTrue(docs.count() == 3);
        docs = coll.find("'2019-2-1' not in $.dateField").execute();
        // System.out.println("Number of rows using NOT IN without casting = "+docs.count());
        assertTrue(docs.count() == 0);
        docs = coll.find("CAST(CAST('2019-2-1' as DATE) as JSON) overlaps $.dateField").execute();
        // System.out.println("Number of rows using OVERLAPS with indexed array = "+docs.count());
        assertTrue(docs.count() == 3);
        docs = coll.find("'2019-2-1' not overlaps $.dateField").execute();
        // System.out.println("Number of rows using NOT OVERLAPS without casting = "+docs.count());
        assertTrue(docs.count() == 0);
        // Integration scenarios for time
        docs = coll.find("CAST(CAST(:timeField as TIME) as JSON) in $.timeField").bind("timeField", "7.30").execute();
        assertTrue(docs.count() == 1);
        docs = coll.find(":timeField not in $.timeField").bind("timeField", "7.30").execute();
        assertTrue(docs.count() == 2);
        docs = coll.find("CAST(CAST(:timeField as TIME) as JSON) overlaps $.timeField").bind("timeField", "7.30").execute();
        assertTrue(docs.count() == 1);
        docs = coll.find(":timeField not overlaps $.timeField").bind("timeField", "7.30").execute();
        assertTrue(docs.count() == 2);
        // Integration scenarios for datetime
        docs = coll.find("CAST(CAST(:datetimeField as DATETIME) as JSON) in $.datetimeField").bind("datetimeField", "9999-12-30 23:59:59").execute();
        assertTrue(docs.count() == 2);
        docs = coll.find(":datetimeField NOT IN $.datetimeField").bind("datetimeField", "9999-12-30 23:59:59").execute();
        assertTrue(docs.count() == 1);
        docs = coll.find("CAST(CAST(:datetimeField as DATETIME) as JSON) OVERLAPS $.datetimeField").bind("datetimeField", "9999-12-30 23:59:59").execute();
        assertTrue(docs.count() == 2);
        docs = coll.find(":datetimeField NOT OVERLAPS $.datetimeField").bind("datetimeField", "9999-12-30 23:59:59").execute();
        assertTrue(docs.count() == 1);
        // Integration scenaris of Integer
        docs = coll.find(":intField not in $.intField").bind("intField", 12).execute();
        assertTrue(docs.count() == 1);
        docs = coll.find(":intField overlaps $.intField").bind("intField", 12).execute();
        assertTrue(docs.count() == 2);
        docs = coll.find(":intField not overlaps $.intField").bind("intField", 12).execute();
        assertTrue(docs.count() == 1);
        // Integration scenaris of unsigned integer
        docs = coll.find(":uintField not in $.uintField").bind("uintField", 52).execute();
        assertTrue(docs.count() == 0);
        docs = coll.find(":uintField overlaps $.uintField").bind("uintField", 52).execute();
        assertTrue(docs.count() == 3);
        docs = coll.find(":uintField not overlaps $.uintField").bind("uintField", 52).execute();
        assertTrue(docs.count() == 0);
        // Integration scenaris of character type
        docs = coll.find(":charField not in $.charField").bind("charField", "abcd1").execute();
        assertTrue(docs.count() == 0);
        docs = coll.find(":charField overlaps $.charField").bind("charField", "abcd1").execute();
        assertTrue(docs.count() == 3);
        docs = coll.find(":charField not overlaps $.charField").bind("charField", "abcd1").execute();
        assertTrue(docs.count() == 0);
        // Integration scenarios of binary type
        docs = coll.find(":binaryField not in $.binaryField").bind("binaryField", "abcd1").execute();
        assertTrue(docs.count() == 0);
        docs = coll.find(":binaryField overlaps $.binaryField").bind("binaryField", "abcd1").execute();
        assertTrue(docs.count() == 3);
        docs = coll.find(":binaryField not overlaps $.binaryField").bind("binaryField", "abcd1").execute();
        assertTrue(docs.count() == 0);
        sch.dropCollection(collname);
    } finally {
        if (sess != null) {
            sess.close();
            sess = null;
        }
    }
}
Also used : SessionFactory(com.mysql.cj.xdevapi.SessionFactory) DbDoc(com.mysql.cj.xdevapi.DbDoc) Schema(com.mysql.cj.xdevapi.Schema) Collection(com.mysql.cj.xdevapi.Collection) JsonString(com.mysql.cj.xdevapi.JsonString) JsonString(com.mysql.cj.xdevapi.JsonString) WrongArgumentException(com.mysql.cj.exceptions.WrongArgumentException) ExecutionException(java.util.concurrent.ExecutionException) DocResult(com.mysql.cj.xdevapi.DocResult) Session(com.mysql.cj.xdevapi.Session) Test(org.junit.jupiter.api.Test)

Aggregations

Schema (com.mysql.cj.xdevapi.Schema)25 Test (org.junit.jupiter.api.Test)23 JsonString (com.mysql.cj.xdevapi.JsonString)18 Session (com.mysql.cj.xdevapi.Session)18 SessionFactory (com.mysql.cj.xdevapi.SessionFactory)16 Collection (com.mysql.cj.xdevapi.Collection)15 WrongArgumentException (com.mysql.cj.exceptions.WrongArgumentException)14 ExecutionException (java.util.concurrent.ExecutionException)14 DocResult (com.mysql.cj.xdevapi.DocResult)3 DbDoc (com.mysql.cj.xdevapi.DbDoc)2 SessionImpl (com.mysql.cj.xdevapi.SessionImpl)2 XProtocolError (com.mysql.cj.protocol.x.XProtocolError)1 Disabled (org.junit.jupiter.api.Disabled)1