use of org.h2.dev.util.BinaryArithmeticStream.In in project ignite by apache.
the class H2DynamicTableSelfTest method testIndexNameConflictCheckDiscovery.
/**
* Tests index name conflict check in discovery thread.
* @throws Exception if failed.
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void testIndexNameConflictCheckDiscovery() throws Exception {
execute(grid(0), "CREATE TABLE \"Person\" (id int primary key, name varchar)");
execute(grid(0), "CREATE INDEX \"idx\" ON \"Person\" (\"name\")");
GridTestUtils.assertThrows(null, new Callable<Object>() {
@Override
public Object call() throws Exception {
QueryEntity e = new QueryEntity();
e.setTableName("City");
e.setKeyFields(Collections.singleton("name"));
e.setFields(new LinkedHashMap<>(Collections.singletonMap("name", String.class.getName())));
e.setIndexes(Collections.singleton(new QueryIndex("name").setName("idx")));
e.setKeyType("CityKey");
e.setValueType("City");
queryProcessor(client()).dynamicTableCreate("PUBLIC", e, CacheMode.PARTITIONED.name(), null, null, null, null, CacheAtomicityMode.ATOMIC, null, 10, false);
return null;
}
}, SchemaOperationException.class, "Index already exists: idx");
}
use of org.h2.dev.util.BinaryArithmeticStream.In in project ignite by apache.
the class GridQueryParsingTest method testParseTableFilter.
/**
* Query AST transformation heavily depends on this behavior.
*
* @throws Exception If failed.
*/
public void testParseTableFilter() throws Exception {
Prepared prepared = parse("select Person.old, p1.old, p1.addrId from Person, Person p1 " + "where exists(select 1 from sch2.Address a where a.id = p1.addrId)");
GridSqlSelect select = (GridSqlSelect) new GridSqlQueryParser(false).parse(prepared);
GridSqlJoin join = (GridSqlJoin) select.from();
GridSqlTable tbl1 = (GridSqlTable) join.leftTable();
GridSqlAlias tbl2Alias = (GridSqlAlias) join.rightTable();
GridSqlTable tbl2 = tbl2Alias.child();
// Must be distinct objects, even if it is the same table.
assertNotSame(tbl1, tbl2);
assertNotNull(tbl1.dataTable());
assertNotNull(tbl2.dataTable());
assertSame(tbl1.dataTable(), tbl2.dataTable());
GridSqlColumn col1 = (GridSqlColumn) select.column(0);
GridSqlColumn col2 = (GridSqlColumn) select.column(1);
assertSame(tbl1, col1.expressionInFrom());
// Alias in FROM must be included in column.
assertSame(tbl2Alias, col2.expressionInFrom());
// In EXISTS we must correctly reference the column from the outer query.
GridSqlAst exists = select.where();
GridSqlSubquery subqry = exists.child();
GridSqlSelect subSelect = subqry.child();
GridSqlColumn p1AddrIdCol = (GridSqlColumn) select.column(2);
assertEquals("ADDRID", p1AddrIdCol.column().getName());
assertSame(tbl2Alias, p1AddrIdCol.expressionInFrom());
GridSqlColumn p1AddrIdColExists = subSelect.where().child(1);
assertEquals("ADDRID", p1AddrIdCol.column().getName());
assertSame(tbl2Alias, p1AddrIdColExists.expressionInFrom());
}
use of org.h2.dev.util.BinaryArithmeticStream.In in project elastic-core-maven by OrdinaryDude.
the class FullTextTrigger method search.
/**
* Search the Lucene index
*
* The result set will have the following columns:
* SCHEMA - Schema name (String)
* TABLE - Table name (String)
* COLUMNS - Primary key column names (String[]) - this is always DB_ID
* KEYS - Primary key values (Long[]) - this is always the DB_ID value for the table row
* SCORE - Lucene score (Float)
*
* @param conn SQL connection
* @param schema Schema name
* @param table Table name
* @param queryText Query expression
* @param limit Number of rows to return
* @param offset Offset with result set
* @return Search results
* @throws SQLException Unable to search the index
*/
public static ResultSet search(Connection conn, String schema, String table, String queryText, int limit, int offset) throws SQLException {
//
// Get Lucene index access
//
getIndexAccess(conn);
//
// Create the result set columns
//
SimpleResultSet result = new SimpleResultSet();
result.addColumn("SCHEMA", Types.VARCHAR, 0, 0);
result.addColumn("TABLE", Types.VARCHAR, 0, 0);
result.addColumn("COLUMNS", Types.ARRAY, 0, 0);
result.addColumn("KEYS", Types.ARRAY, 0, 0);
result.addColumn("SCORE", Types.FLOAT, 0, 0);
//
// Perform the search
//
// The _QUERY field contains the table and row identification (schema.table;keyName;keyValue)
// The _TABLE field is used to limit the search results to the current table
// The _DATA field contains the indexed row data (this is the default search field)
// The _MODIFIED field contains the row modification time (YYYYMMDDhhmmss) in GMT
//
indexLock.readLock().lock();
try {
QueryParser parser = new QueryParser("_DATA", analyzer);
parser.setDateResolution("_MODIFIED", DateTools.Resolution.SECOND);
parser.setDefaultOperator(QueryParser.Operator.AND);
Query query = parser.parse("_TABLE:" + schema.toUpperCase() + "." + table.toUpperCase() + " AND (" + queryText + ")");
TopDocs documents = indexSearcher.search(query, limit);
ScoreDoc[] hits = documents.scoreDocs;
int resultCount = Math.min(hits.length, (limit == 0 ? hits.length : limit));
int resultOffset = Math.min(offset, resultCount);
for (int i = resultOffset; i < resultCount; i++) {
Document document = indexSearcher.doc(hits[i].doc);
String[] indexParts = document.get("_QUERY").split(";");
String[] nameParts = indexParts[0].split("\\.");
result.addRow(nameParts[0], nameParts[1], new String[] { indexParts[1] }, new Long[] { Long.parseLong(indexParts[2]) }, hits[i].score);
}
} catch (ParseException exc) {
Logger.logDebugMessage("Lucene parse exception for query: " + queryText + "\n" + exc.getMessage());
throw new SQLException("Lucene parse exception for query: " + queryText + "\n" + exc.getMessage());
} catch (IOException exc) {
Logger.logErrorMessage("Unable to search Lucene index", exc);
throw new SQLException("Unable to search Lucene index", exc);
} finally {
indexLock.readLock().unlock();
}
return result;
}
use of org.h2.dev.util.BinaryArithmeticStream.In in project spf4j by zolyfarkas.
the class JdbcSemaphoreTest method testSingleMultipleInstance.
@Test(expected = SQLException.class)
public void testSingleMultipleInstance() throws SQLException, IOException, InterruptedException, TimeoutException {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:test");
ds.setUser("sa");
ds.setPassword("sa");
try (Connection conn = ds.getConnection()) {
// only to keep the schema arround in this section
createSchemaObjects(ds);
JdbcLock lock = new JdbcLock(ds, SemaphoreTablesDesc.DEFAULT, "testLock", 10);
JdbcLock lock2 = new JdbcLock(ds, SemaphoreTablesDesc.DEFAULT, "testLock", 10);
lock.lock();
Assert.assertFalse(lock.tryLock());
lock.unlock();
lock2.lock();
lock.unlock();
}
}
use of org.h2.dev.util.BinaryArithmeticStream.In in project spf4j by zolyfarkas.
the class JdbcSemaphoreTest method testSingleProcess.
@Test
public void testSingleProcess() throws SQLException, IOException, InterruptedException, TimeoutException {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:test");
ds.setUser("sa");
ds.setPassword("sa");
try (Connection conn = ds.getConnection()) {
// only to keep the schema arround in thsi section
createSchemaObjects(ds);
JdbcHeartBeat heartbeat = JdbcHeartBeat.getHeartBeatAndSubscribe(ds, HeartBeatTableDesc.DEFAULT, (JdbcHeartBeat.LifecycleHook) null);
long lb = heartbeat.getLastRunDB();
LOG.debug("last TS = {}", Instant.ofEpochMilli(lb));
heartbeat.beat();
testReleaseAck(ds, "testSem", 2);
testReleaseAck(ds, "testSem2", 2);
heartbeat.close();
}
}
Aggregations