use of com.mysql.cj.xdevapi.SessionFactory in project aws-mysql-jdbc by awslabs.
the class InternalXBaseTestCase method mysqlVersionMeetsMinimum.
/**
* Checks if the MySQL version we are connected to meets the minimum {@link ServerVersion} provided.
*
* @param url
* server URL
* @param version
* the minimum {@link ServerVersion} accepted
* @return true or false according to versions comparison
*/
protected boolean mysqlVersionMeetsMinimum(String url, ServerVersion version) {
if (this.isSetForXTests) {
if (this.mysqlVersion == null) {
Session session = new SessionFactory().getSession(url);
this.mysqlVersion = ServerVersion.parseVersion(session.sql("SELECT version()").execute().fetchOne().getString(0));
session.close();
}
return this.mysqlVersion.meetsMinimum(version);
}
return false;
}
use of com.mysql.cj.xdevapi.SessionFactory in project aws-mysql-jdbc by awslabs.
the class CollectionTest method testArrayIndex013.
@Test
public void testArrayIndex013() 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);
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();
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]}").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\" : [51.2,52.7,53.6]}").execute();
/* 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]}").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]}").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\" : [51.2,52.7,53.6]}").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"));
}
sch.dropCollection(collname);
} finally {
if (sess != null) {
sess.close();
sess = null;
}
}
}
use of com.mysql.cj.xdevapi.SessionFactory in project aws-mysql-jdbc by awslabs.
the class CollectionTest method testArrayIndex006.
@Test
public void testArrayIndex006() 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("multiArrayIndex", "{\"fields\": [{\"field\": \"$.intField\", \"type\": \"INTEGER\", \"array\": false}," + "{\"field\": \"$.charField\", \"type\": \"CHAR(255)\", \"array\": false}," + "{\"field\": \"$.decimalField\", \"type\": \"DECIMAL\", \"array\": true}," + "{\"field\": \"$.dateField\", \"type\": \"DATE\", \"array\": false}," + "{\"field\": \"$.timeField\", \"type\": \"TIME\", \"array\": false}," + "{\"field\": \"$.datetimeField\", \"type\": \"DATETIME\", \"array\": false}]}");
validateArrayIndex("multiArrayIndex", "coll1", 6);
coll.add("{\"intField\" : 12, \"uintField\" : [51,52,53], \"dateField\" : \"2019-1-1\", \"datetimeField\" : \"9999-12-31 23:59:59\", \"charField\" : \"abcd1\", \"binaryField\" : \"abcd1\", \"timeField\" : \"10.30\", \"decimalField\" : [51.2, 57.6, 55.8]}").execute();
coll.add("{\"intField\" : 12, \"uintField\" : [51,52,53], \"dateField\" : \"2019-1-1\", \"datetimeField\" : \"9999-12-31 23:59:59\", \"charField\" : \"abcd1\", \"binaryField\" : \"abcd1\", \"timeField\" : \"10.30\", \"decimalField\" : [51.2, 57.6, 55.8]}").execute();
coll.add("{\"intField\" : 12, \"uintField\" : [51,52,53], \"dateField\" : \"2019-1-1\", \"datetimeField\" : \"9999-12-31 23:59:59\", \"charField\" : \"abcd1\", \"binaryField\" : \"abcd1\", \"timeField\" : \"10.30\", \"decimalField\" : [51.2, 57.6, 55.8]}").execute();
coll.add("{\"intField\" : 18, \"uintField\" : [51,52,53], \"dateField\" : \"2019-1-1\", \"datetimeField\" : \"9999-12-31 23:59:59\", \"charField\" : \"abcd1\", \"binaryField\" : \"abcd1\", \"timeField\" : \"10.30\", \"decimalField\" : [51.2, 57.6, 55.8]}").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("Invalid JSON value for CAST to INTEGER from column json_extract at row"));
}
try {
coll.add("{\"intField\" : 12, \"dateField\" : \"2019-1-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("Incorrect time value"));
}
sch.dropCollection(collname);
} finally {
if (sess != null) {
sess.close();
sess = null;
}
}
}
use of com.mysql.cj.xdevapi.SessionFactory in project aws-mysql-jdbc by awslabs.
the class CollectionTest method testArrayIndex007.
@Test
public void testArrayIndex007() 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("multiArrayIndex", "{\"fields\": [{\"field\": \"$.intField\", \"type\": \"INTEGER\", \"array\": false}," + "{\"field\": \"$.charField\", \"type\": \"CHAR(255)\", \"array\": false}," + "{\"field\": \"$.decimalField\", \"type\": \"DECIMAL\", \"array\": false}," + "{\"field\": \"$.dateField\", \"type\": \"DATE\", \"array\": false}," + "{\"field\": \"$.timeField\", \"type\": \"TIME\", \"array\": false}," + "{\"field\": \"$.datetimeField\", \"type\": \"DATETIME\", \"array\": true}]}");
validateArrayIndex("multiArrayIndex", "coll1", 6);
coll.add("{\"intField\" : 12, \"uintField\" : [51,52,53], \"dateField\" : \"2019-1-1\", \"datetimeField\" : [\"9999-12-31 23:59:59\", \"9999-12-31 23:59:59\", \"9999-12-31 23:59:59\"], \"charField\" : \"abcd1\", \"binaryField\" : \"abcd1\", \"timeField\" : \"10.30\", \"decimalField\" : 51.2}").execute();
coll.add("{\"intField\" : 12, \"uintField\" : [51,52,53], \"dateField\" : \"2019-1-1\", \"datetimeField\" : [\"9999-12-31 23:59:59\", \"9999-12-31 23:59:59\", \"9999-12-31 23:59:59\"], \"charField\" : \"abcd1\", \"binaryField\" : \"abcd1\", \"timeField\" : \"10.30\", \"decimalField\" : 51.2}").execute();
coll.add("{\"intField\" : 12, \"uintField\" : [51,52,53], \"dateField\" : \"2019-1-1\", \"datetimeField\" : [\"9999-12-31 23:59:59\", \"9999-12-31 23:59:59\", \"9999-12-31 23:59:59\"], \"charField\" : \"abcd1\", \"binaryField\" : \"abcd1\", \"timeField\" : \"10.30\", \"decimalField\" : 51.2}").execute();
coll.add("{\"intField\" : 18, \"uintField\" : [51,52,53], \"dateField\" : \"2019-1-1\", \"datetimeField\" : [\"9999-12-31 23:59:59\", \"9999-12-31 23:59:59\", \"9999-12-31 23:59:59\"], \"charField\" : \"abcd1\", \"binaryField\" : \"abcd1\", \"timeField\" : \"10.30\", \"decimalField\" : 51.2}").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("Invalid JSON value for CAST to INTEGER from column json_extract at row"));
}
try {
coll.add("{\"intField\" : 12, \"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("Incorrect date value"));
}
sch.dropCollection(collname);
} finally {
if (sess != null) {
sess.close();
sess = null;
}
}
}
use of com.mysql.cj.xdevapi.SessionFactory in project aws-mysql-jdbc by awslabs.
the class CollectionTest method testArrayIndex002.
/**
* START testArrayIndexBasic tests
*
* @throws Exception
*/
// @Test
public void testArrayIndex002() throws Exception {
System.out.println("testCreateIndexSanity");
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, \"required\": true}]}");
coll.createIndex("dateArrayIndex", "{\"fields\": [{\"field\": \"$.dateField\", \"type\": \"DATE\", \"array\": true, \"required\": true}]}");
coll.createIndex("charArrayIndex", "{\"fields\": [{\"field\": \"$.charField\", \"type\": \"CHAR(256)\", \"array\": true, \"required\": true}]}");
coll.createIndex("timeArrayIndex", "{\"fields\": [{\"field\": \"$.timeField\", \"type\": \"TIME\", \"array\": true, \"required\": true}]}");
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();
try {
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();
assertTrue(false);
} catch (Exception e) {
System.out.println("ERROR : " + e.getMessage());
assertTrue(e.getMessage().contains("Document is missing a required field"));
}
try {
coll.add("{\"intField\" : [1,2,3], \"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("Document is missing a required field"));
}
try {
coll.add("{\"intField\" : [11,12,3], \"dateField\" : [\"2019-1-1\", \"2019-2-1\", \"2019-3-1\"], \"timeField\" : [\"10.30\", \"11.30\", \"12.30\"]}").execute();
assertTrue(false);
} catch (Exception e) {
System.out.println("ERROR : " + e.getMessage());
assertTrue(e.getMessage().contains("Document is missing a required field"));
}
try {
coll.add("{\"intField\" : [11,12,3], \"dateField\" : [\"2019-1-1\", \"2019-2-1\", \"2019-3-1\"], \"charField\" : [\"abcd1\", \"abcd1\", \"abcd2\", \"abcd4\"]}").execute();
assertTrue(false);
} catch (Exception e) {
System.out.println("ERROR : " + e.getMessage());
assertTrue(e.getMessage().contains("Document is missing a required field"));
}
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"));
}
try {
coll.add("{\"intField\" : 12, \"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;
}
}
}
Aggregations