use of com.mysql.cj.xdevapi.SessionFactory in project aws-mysql-jdbc by awslabs.
the class CollectionRemoveTest method testPreparedStatements.
@Test
public void testPreparedStatements() {
assumeTrue(mysqlVersionMeetsMinimum(ServerVersion.parseVersion("8.0.14")), "MySQL 8.0.14+ is required to run this test.");
try {
// Prepare test data.
testPreparedStatementsResetData();
SessionFactory sf = new SessionFactory();
/*
* Test common usage.
*/
Session testSession = sf.getSession(this.testProperties);
int sessionThreadId = getThreadId(testSession);
assertPreparedStatementsCount(sessionThreadId, 0, 1);
assertPreparedStatementsStatusCounts(testSession, 0, 0, 0);
Collection testCol1 = testSession.getDefaultSchema().getCollection(this.collectionName + "_1");
Collection testCol2 = testSession.getDefaultSchema().getCollection(this.collectionName + "_2");
Collection testCol3 = testSession.getDefaultSchema().getCollection(this.collectionName + "_3");
Collection testCol4 = testSession.getDefaultSchema().getCollection(this.collectionName + "_4");
// Initialize several RemoveStatement objects.
// Remove all.
RemoveStatement testRemove1 = testCol1.remove("true");
// Criteria with one placeholder.
RemoveStatement testRemove2 = testCol2.remove("$.ord >= :n");
// Criteria with same placeholder repeated.
RemoveStatement testRemove3 = testCol3.remove("$.ord >= :n AND $.ord <= :n + 1");
// Criteria with multiple placeholders.
RemoveStatement testRemove4 = testCol4.remove("$.ord >= :n AND $.ord <= :m");
assertPreparedStatementsCountsAndId(testSession, 0, testRemove1, 0, -1);
assertPreparedStatementsCountsAndId(testSession, 0, testRemove2, 0, -1);
assertPreparedStatementsCountsAndId(testSession, 0, testRemove3, 0, -1);
assertPreparedStatementsCountsAndId(testSession, 0, testRemove4, 0, -1);
// A. Set binds: 1st execute -> non-prepared.
assertTestPreparedStatementsResult(testRemove1.execute(), 4, testCol1.getName());
assertPreparedStatementsCountsAndId(testSession, 0, testRemove1, 0, -1);
assertTestPreparedStatementsResult(testRemove2.bind("n", 2).execute(), 3, testCol2.getName(), 1);
assertPreparedStatementsCountsAndId(testSession, 0, testRemove2, 0, -1);
assertTestPreparedStatementsResult(testRemove3.bind("n", 2).execute(), 2, testCol3.getName(), 1, 4);
assertPreparedStatementsCountsAndId(testSession, 0, testRemove3, 0, -1);
assertTestPreparedStatementsResult(testRemove4.bind("n", 2).bind("m", 3).execute(), 2, testCol4.getName(), 1, 4);
assertPreparedStatementsCountsAndId(testSession, 0, testRemove4, 0, -1);
assertPreparedStatementsStatusCounts(testSession, 0, 0, 0);
testPreparedStatementsResetData();
// B. Set sort resets execution count: 1st execute -> non-prepared.
assertTestPreparedStatementsResult(testRemove1.sort("$._id").execute(), 4, testCol1.getName());
assertPreparedStatementsCountsAndId(testSession, 0, testRemove1, 0, -1);
assertTestPreparedStatementsResult(testRemove2.sort("$._id").execute(), 3, testCol2.getName(), 1);
assertPreparedStatementsCountsAndId(testSession, 0, testRemove2, 0, -1);
assertTestPreparedStatementsResult(testRemove3.sort("$._id").execute(), 2, testCol3.getName(), 1, 4);
assertPreparedStatementsCountsAndId(testSession, 0, testRemove3, 0, -1);
assertTestPreparedStatementsResult(testRemove4.sort("$._id").execute(), 2, testCol4.getName(), 1, 4);
assertPreparedStatementsCountsAndId(testSession, 0, testRemove4, 0, -1);
assertPreparedStatementsStatusCounts(testSession, 0, 0, 0);
testPreparedStatementsResetData();
// C. Set binds reuse statement: 2nd execute -> prepare + execute.
assertTestPreparedStatementsResult(testRemove1.execute(), 4, testCol1.getName());
assertPreparedStatementsCountsAndId(testSession, 1, testRemove1, 1, 1);
assertTestPreparedStatementsResult(testRemove2.bind("n", 3).execute(), 2, testCol2.getName(), 1, 2);
assertPreparedStatementsCountsAndId(testSession, 2, testRemove2, 2, 1);
assertTestPreparedStatementsResult(testRemove3.bind("n", 3).execute(), 2, testCol3.getName(), 1, 2);
assertPreparedStatementsCountsAndId(testSession, 3, testRemove3, 3, 1);
assertTestPreparedStatementsResult(testRemove4.bind("m", 4).execute(), 3, testCol4.getName(), 1);
assertPreparedStatementsCountsAndId(testSession, 4, testRemove4, 4, 1);
assertPreparedStatementsStatusCounts(testSession, 4, 4, 0);
testPreparedStatementsResetData();
// D. Set binds reuse statement: 3rd execute -> execute.
assertTestPreparedStatementsResult(testRemove1.execute(), 4, testCol1.getName());
assertPreparedStatementsCountsAndId(testSession, 4, testRemove1, 1, 2);
assertTestPreparedStatementsResult(testRemove2.bind("n", 4).execute(), 1, testCol2.getName(), 1, 2, 3);
assertPreparedStatementsCountsAndId(testSession, 4, testRemove2, 2, 2);
assertTestPreparedStatementsResult(testRemove3.bind("n", 1).execute(), 2, testCol3.getName(), 3, 4);
assertPreparedStatementsCountsAndId(testSession, 4, testRemove3, 3, 2);
assertTestPreparedStatementsResult(testRemove4.bind("m", 2).execute(), 1, testCol4.getName(), 1, 3, 4);
assertPreparedStatementsCountsAndId(testSession, 4, testRemove4, 4, 2);
assertPreparedStatementsStatusCounts(testSession, 4, 8, 0);
testPreparedStatementsResetData();
// E. Set sort deallocates and resets execution count: 1st execute -> deallocate + non-prepared.
assertTestPreparedStatementsResult(testRemove1.sort("$._id").execute(), 4, testCol1.getName());
assertPreparedStatementsCountsAndId(testSession, 3, testRemove1, 0, -1);
assertTestPreparedStatementsResult(testRemove2.sort("$._id").execute(), 1, testCol2.getName(), 1, 2, 3);
assertPreparedStatementsCountsAndId(testSession, 2, testRemove2, 0, -1);
assertTestPreparedStatementsResult(testRemove3.sort("$._id").execute(), 2, testCol3.getName(), 3, 4);
assertPreparedStatementsCountsAndId(testSession, 1, testRemove3, 0, -1);
assertTestPreparedStatementsResult(testRemove4.sort("$._id").execute(), 1, testCol4.getName(), 1, 3, 4);
assertPreparedStatementsCountsAndId(testSession, 0, testRemove4, 0, -1);
assertPreparedStatementsStatusCounts(testSession, 4, 8, 4);
testPreparedStatementsResetData();
// F. No Changes: 2nd execute -> prepare + execute.
assertTestPreparedStatementsResult(testRemove1.execute(), 4, testCol1.getName());
assertPreparedStatementsCountsAndId(testSession, 1, testRemove1, 1, 1);
assertTestPreparedStatementsResult(testRemove2.execute(), 1, testCol2.getName(), 1, 2, 3);
assertPreparedStatementsCountsAndId(testSession, 2, testRemove2, 2, 1);
assertTestPreparedStatementsResult(testRemove3.execute(), 2, testCol3.getName(), 3, 4);
assertPreparedStatementsCountsAndId(testSession, 3, testRemove3, 3, 1);
assertTestPreparedStatementsResult(testRemove4.execute(), 1, testCol4.getName(), 1, 3, 4);
assertPreparedStatementsCountsAndId(testSession, 4, testRemove4, 4, 1);
assertPreparedStatementsStatusCounts(testSession, 8, 12, 4);
testPreparedStatementsResetData();
// G. Set limit for the first time deallocates and re-prepares: 1st execute -> re-prepare + execute.
assertTestPreparedStatementsResult(testRemove1.limit(1).execute(), 1, testCol1.getName(), 2, 3, 4);
assertPreparedStatementsCountsAndId(testSession, 4, testRemove1, 1, 1);
assertTestPreparedStatementsResult(testRemove2.limit(1).execute(), 1, testCol2.getName(), 1, 2, 3);
assertPreparedStatementsCountsAndId(testSession, 4, testRemove2, 2, 1);
assertTestPreparedStatementsResult(testRemove3.limit(1).execute(), 1, testCol3.getName(), 2, 3, 4);
assertPreparedStatementsCountsAndId(testSession, 4, testRemove3, 3, 1);
assertTestPreparedStatementsResult(testRemove4.limit(1).execute(), 1, testCol4.getName(), 1, 3, 4);
assertPreparedStatementsCountsAndId(testSession, 4, testRemove4, 4, 1);
assertPreparedStatementsStatusCounts(testSession, 12, 16, 8);
testPreparedStatementsResetData();
// H. Set limit reuse prepared statement: 2nd execute -> execute.
assertTestPreparedStatementsResult(testRemove1.limit(2).execute(), 2, testCol1.getName(), 3, 4);
assertPreparedStatementsCountsAndId(testSession, 4, testRemove1, 1, 2);
assertTestPreparedStatementsResult(testRemove2.limit(2).execute(), 1, testCol2.getName(), 1, 2, 3);
assertPreparedStatementsCountsAndId(testSession, 4, testRemove2, 2, 2);
assertTestPreparedStatementsResult(testRemove3.limit(2).execute(), 2, testCol3.getName(), 3, 4);
assertPreparedStatementsCountsAndId(testSession, 4, testRemove3, 3, 2);
assertTestPreparedStatementsResult(testRemove4.limit(2).execute(), 1, testCol4.getName(), 1, 3, 4);
assertPreparedStatementsCountsAndId(testSession, 4, testRemove4, 4, 2);
assertPreparedStatementsStatusCounts(testSession, 12, 20, 8);
testPreparedStatementsResetData();
// I. Set sort deallocates and resets execution count, set limit has no effect: 1st execute -> deallocate + non-prepared.
assertTestPreparedStatementsResult(testRemove1.sort("$._id").limit(1).execute(), 1, testCol1.getName(), 2, 3, 4);
assertPreparedStatementsCountsAndId(testSession, 3, testRemove1, 0, -1);
assertTestPreparedStatementsResult(testRemove2.sort("$._id").limit(1).execute(), 1, testCol2.getName(), 1, 2, 3);
assertPreparedStatementsCountsAndId(testSession, 2, testRemove2, 0, -1);
assertTestPreparedStatementsResult(testRemove3.sort("$._id").limit(1).execute(), 1, testCol3.getName(), 2, 3, 4);
assertPreparedStatementsCountsAndId(testSession, 1, testRemove3, 0, -1);
assertTestPreparedStatementsResult(testRemove4.sort("$._id").limit(1).execute(), 1, testCol4.getName(), 1, 3, 4);
assertPreparedStatementsCountsAndId(testSession, 0, testRemove4, 0, -1);
assertPreparedStatementsStatusCounts(testSession, 12, 20, 12);
testPreparedStatementsResetData();
// J. Set limit reuse statement: 2nd execute -> prepare + execute.
assertTestPreparedStatementsResult(testRemove1.limit(2).execute(), 2, testCol1.getName(), 3, 4);
assertPreparedStatementsCountsAndId(testSession, 1, testRemove1, 1, 1);
assertTestPreparedStatementsResult(testRemove2.limit(2).execute(), 1, testCol2.getName(), 1, 2, 3);
assertPreparedStatementsCountsAndId(testSession, 2, testRemove2, 2, 1);
assertTestPreparedStatementsResult(testRemove3.limit(2).execute(), 2, testCol3.getName(), 3, 4);
assertPreparedStatementsCountsAndId(testSession, 3, testRemove3, 3, 1);
assertTestPreparedStatementsResult(testRemove4.limit(2).execute(), 1, testCol4.getName(), 1, 3, 4);
assertPreparedStatementsCountsAndId(testSession, 4, testRemove4, 4, 1);
assertPreparedStatementsStatusCounts(testSession, 16, 24, 12);
testPreparedStatementsResetData();
testSession.close();
// Prepared statements won't live past the closing of the session.
assertPreparedStatementsCount(sessionThreadId, 0, 10);
/*
* Test falling back onto non-prepared statements.
*/
testSession = sf.getSession(this.testProperties);
int origMaxPrepStmtCount = this.session.sql("SELECT @@max_prepared_stmt_count").execute().fetchOne().getInt(0);
try {
// Allow preparing only one more statement.
this.session.sql("SET GLOBAL max_prepared_stmt_count = ?").bind(getPreparedStatementsCount() + 1).execute();
sessionThreadId = getThreadId(testSession);
assertPreparedStatementsCount(sessionThreadId, 0, 1);
assertPreparedStatementsStatusCounts(testSession, 0, 0, 0);
testCol1 = testSession.getDefaultSchema().getCollection(this.collectionName + "_1");
testCol2 = testSession.getDefaultSchema().getCollection(this.collectionName + "_2");
testRemove1 = testCol1.remove("true");
testRemove2 = testCol2.remove("true");
// 1st execute -> don't prepare.
assertTestPreparedStatementsResult(testRemove1.execute(), 4, testCol1.getName());
assertPreparedStatementsCountsAndId(testSession, 0, testRemove1, 0, -1);
assertTestPreparedStatementsResult(testRemove2.execute(), 4, testCol2.getName());
assertPreparedStatementsCountsAndId(testSession, 0, testRemove2, 0, -1);
assertPreparedStatementsStatusCounts(testSession, 0, 0, 0);
testPreparedStatementsResetData();
// 2nd execute -> prepare + execute.
assertTestPreparedStatementsResult(testRemove1.execute(), 4, testCol1.getName());
assertPreparedStatementsCountsAndId(testSession, 1, testRemove1, 1, 1);
// Fails preparing, execute as non-prepared.
assertTestPreparedStatementsResult(testRemove2.execute(), 4, testCol2.getName());
assertPreparedStatementsCountsAndId(testSession, 1, testRemove2, 0, -1);
// Failed prepare also counts.
assertPreparedStatementsStatusCounts(testSession, 2, 1, 0);
testPreparedStatementsResetData();
// 3rd execute -> execute.
assertTestPreparedStatementsResult(testRemove1.execute(), 4, testCol1.getName());
assertPreparedStatementsCountsAndId(testSession, 1, testRemove1, 1, 2);
// Execute as non-prepared.
assertTestPreparedStatementsResult(testRemove2.execute(), 4, testCol2.getName());
assertPreparedStatementsCountsAndId(testSession, 1, testRemove2, 0, -1);
assertPreparedStatementsStatusCounts(testSession, 2, 2, 0);
testPreparedStatementsResetData();
testSession.close();
// Prepared statements won't live past the closing of the session.
assertPreparedStatementsCount(sessionThreadId, 0, 10);
} finally {
this.session.sql("SET GLOBAL max_prepared_stmt_count = ?").bind(origMaxPrepStmtCount).execute();
}
} finally {
for (int i = 0; i < 4; i++) {
dropCollection(this.collectionName + "_" + (i + 1));
}
}
}
use of com.mysql.cj.xdevapi.SessionFactory 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;
}
}
}
use of com.mysql.cj.xdevapi.SessionFactory 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;
}
}
}
use of com.mysql.cj.xdevapi.SessionFactory 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;
}
}
}
use of com.mysql.cj.xdevapi.SessionFactory 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;
}
}
}
Aggregations