use of com.mysql.cj.xdevapi.FilterParams in project aws-mysql-jdbc by awslabs.
the class XProtocolTest method tableInsert.
@Test
public void tableInsert() {
assumeTrue(this.isSetForXTests, PropertyDefinitions.SYSP_testsuite_url_mysqlx + " must be set to run this test.");
this.protocol.send(this.messageBuilder.buildSqlStatement("drop table if exists tableInsert"), 0);
this.protocol.readQueryResult(new StatementExecuteOkBuilder());
this.protocol.send(this.messageBuilder.buildSqlStatement("create table tableInsert (x int, y varchar(20), z decimal(10, 2))"), 0);
this.protocol.readQueryResult(new StatementExecuteOkBuilder());
InsertParams insertParams = new InsertParams();
insertParams.setProjection(new String[] { "z", "x", "y" });
insertParams.addRow(Arrays.asList("10.2", 40, "some string value"));
insertParams.addRow(Arrays.asList("10.3", 50, "another string value"));
this.protocol.send(this.messageBuilder.buildRowInsert(getTestDatabase(), "tableInsert", insertParams), 0);
SqlResult res = this.protocol.readQueryResult(new SqlResultBuilder(this.protocol.getServerSession().getDefaultTimeZone(), this.protocol.getPropertySet()));
assertEquals(2, res.getAffectedItemsCount());
FilterParams filterParams = new TableFilterParams(getTestDatabase(), "tableInsert");
filterParams.setOrder("x DESC");
filterParams.setFields("z, y, x");
this.protocol.send(this.messageBuilder.buildFind(filterParams), 0);
ColumnDefinition metadata = this.protocol.readMetadata();
Iterator<Row> ris = new XProtocolRowInputStream(metadata, this.protocol, null);
Row r = ris.next();
assertEquals("10.30", r.getValue(0, new StringValueFactory(this.protocol.getPropertySet())));
assertEquals("another string value", r.getValue(1, new StringValueFactory(this.protocol.getPropertySet())));
assertEquals("50", r.getValue(2, new StringValueFactory(this.protocol.getPropertySet())));
r = ris.next();
assertEquals("10.20", r.getValue(0, new StringValueFactory(this.protocol.getPropertySet())));
assertEquals("some string value", r.getValue(1, new StringValueFactory(this.protocol.getPropertySet())));
assertEquals("40", r.getValue(2, new StringValueFactory(this.protocol.getPropertySet())));
this.protocol.readQueryResult(new StatementExecuteOkBuilder());
this.protocol.send(this.messageBuilder.buildSqlStatement("drop table tableInsert"), 0);
this.protocol.readQueryResult(new StatementExecuteOkBuilder());
}
use of com.mysql.cj.xdevapi.FilterParams in project aws-mysql-jdbc by awslabs.
the class MysqlxSessionTest method testInterleavedResults.
@Test
public void testInterleavedResults() {
assumeTrue(this.isSetForXTests, PropertyDefinitions.SYSP_testsuite_url_mysqlx + " must be set to run this test.");
XMessageBuilder builder = (XMessageBuilder) this.session.<XMessage>getMessageBuilder();
String collName = "testInterleavedResults";
try {
try {
this.session.query(builder.buildDropCollection(getTestDatabase(), collName), new UpdateResultBuilder<>());
} catch (XProtocolError e) {
if (e.getErrorCode() != MysqlErrorNumbers.ER_BAD_TABLE_ERROR) {
throw e;
}
}
this.session.query(builder.buildCreateCollection(getTestDatabase(), collName), new UpdateResultBuilder<>());
List<String> stringDocs = new ArrayList<>();
stringDocs.add("{'_id':'0'}");
stringDocs.add("{'_id':'1'}");
stringDocs.add("{'_id':'2'}");
stringDocs.add("{'_id':'3'}");
stringDocs.add("{'_id':'4'}");
stringDocs = stringDocs.stream().map(s -> s.replaceAll("'", "\"")).collect(Collectors.toList());
this.session.query(builder.buildDocInsert(getTestDatabase(), collName, stringDocs, false), new UpdateResultBuilder<>());
FilterParams filterParams = new DocFilterParams(getTestDatabase(), collName);
filterParams.setOrder("$._id");
DocResult docs1 = this.session.query(((XMessageBuilder) this.session.<XMessage>getMessageBuilder()).buildFind(filterParams), new StreamingDocResultBuilder(this.session));
DocResult docs2 = this.session.query(((XMessageBuilder) this.session.<XMessage>getMessageBuilder()).buildFind(filterParams), new StreamingDocResultBuilder(this.session));
DocResult docs3 = this.session.query(((XMessageBuilder) this.session.<XMessage>getMessageBuilder()).buildFind(filterParams), new StreamingDocResultBuilder(this.session));
DocResult docs4 = this.session.query(((XMessageBuilder) this.session.<XMessage>getMessageBuilder()).buildFind(filterParams), new StreamingDocResultBuilder(this.session));
DocResult docs5 = this.session.query(((XMessageBuilder) this.session.<XMessage>getMessageBuilder()).buildFind(filterParams), new StreamingDocResultBuilder(this.session));
assertTrue(docs5.hasNext());
assertTrue(docs4.hasNext());
assertTrue(docs3.hasNext());
assertTrue(docs2.hasNext());
assertTrue(docs1.hasNext());
for (int i = 0; i < 5; ++i) {
assertEquals("{\n\"_id\" : \"" + i + "\"\n}", docs1.next().toFormattedString());
assertEquals("{\n\"_id\" : \"" + i + "\"\n}", docs2.next().toFormattedString());
assertEquals("{\n\"_id\" : \"" + i + "\"\n}", docs3.next().toFormattedString());
assertEquals("{\n\"_id\" : \"" + i + "\"\n}", docs4.next().toFormattedString());
assertEquals("{\n\"_id\" : \"" + i + "\"\n}", docs5.next().toFormattedString());
}
assertFalse(docs5.hasNext());
assertFalse(docs4.hasNext());
assertFalse(docs3.hasNext());
assertFalse(docs2.hasNext());
assertFalse(docs1.hasNext());
// let the session be closed with all of these "open"
} finally {
try {
this.session.query(builder.buildDropCollection(getTestDatabase(), collName), new UpdateResultBuilder<>());
} catch (XProtocolError e) {
if (e.getErrorCode() != MysqlErrorNumbers.ER_BAD_TABLE_ERROR) {
throw e;
}
}
}
}
use of com.mysql.cj.xdevapi.FilterParams in project aws-mysql-jdbc by awslabs.
the class XProtocolTest method testMultiInsert.
@Test
public void testMultiInsert() {
assumeTrue(this.isSetForXTests, PropertyDefinitions.SYSP_testsuite_url_mysqlx + " must be set to run this test.");
try {
String collName = createTempTestCollection(this.protocol);
List<String> stringDocs = new ArrayList<>();
stringDocs.add("{'a': 'A', 'a1': 'A1', '_id': 'a'}");
stringDocs.add("{'b': 'B', 'b2': 'B2', '_id': 'b'}");
stringDocs.add("{'c': 'C', 'c3': 'C3', '_id': 'c'}");
stringDocs = stringDocs.stream().map(s -> s.replaceAll("'", "\"")).collect(Collectors.toList());
this.protocol.send(this.messageBuilder.buildDocInsert(getTestDatabase(), collName, stringDocs, false), 0);
this.protocol.readQueryResult(new StatementExecuteOkBuilder());
FilterParams filterParams = new DocFilterParams(getTestDatabase(), collName);
filterParams.setOrder("_id");
this.protocol.send(this.messageBuilder.buildFind(filterParams), 0);
ColumnDefinition metadata = this.protocol.readMetadata();
Iterator<Row> ris = new XProtocolRowInputStream(metadata, this.protocol, null);
Row r = ris.next();
assertEquals(stringDocs.get(0), r.getValue(0, new StringValueFactory(this.protocol.getPropertySet())));
r = ris.next();
assertEquals(stringDocs.get(1), r.getValue(0, new StringValueFactory(this.protocol.getPropertySet())));
r = ris.next();
assertEquals(stringDocs.get(2), r.getValue(0, new StringValueFactory(this.protocol.getPropertySet())));
this.protocol.readQueryResult(new StatementExecuteOkBuilder());
} finally {
dropTempTestCollection(this.protocol);
}
}
use of com.mysql.cj.xdevapi.FilterParams in project aws-mysql-jdbc by awslabs.
the class XProtocolTest method testBasicCrudInsertFind.
@Test
public void testBasicCrudInsertFind() {
assumeTrue(this.isSetForXTests, PropertyDefinitions.SYSP_testsuite_url_mysqlx + " must be set to run this test.");
try {
String collName = createTempTestCollection(this.protocol);
String json = "{'_id': '85983efc2a9a11e5b345feff819cdc9f', 'testVal': 1, 'insertedBy': 'Jess'}".replaceAll("'", "\"");
this.protocol.send(this.messageBuilder.buildDocInsert(getTestDatabase(), collName, Arrays.asList(new String[] { json }), false), 0);
this.protocol.readQueryResult(new StatementExecuteOkBuilder());
FilterParams filterParams = new DocFilterParams(getTestDatabase(), collName);
filterParams.setCriteria("$.testVal = 2-1");
this.protocol.send(this.messageBuilder.buildFind(filterParams), 0);
ColumnDefinition metadata = this.protocol.readMetadata();
Iterator<Row> ris = new XProtocolRowInputStream(metadata, this.protocol, null);
Row r = ris.next();
assertEquals(json, r.getValue(0, new StringValueFactory(this.protocol.getPropertySet())));
this.protocol.readQueryResult(new StatementExecuteOkBuilder());
} finally {
dropTempTestCollection(this.protocol);
}
}
Aggregations