use of datawave.query.config.ShardQueryConfiguration in project datawave by NationalSecurityAgency.
the class QueryPlanTest method verifyQueryStringUpdatesWithQueryTree.
@Test
public void verifyQueryStringUpdatesWithQueryTree() throws ParseException {
ShardQueryConfiguration config = new ShardQueryConfiguration();
config.setQueryString("1");
assertEquals("1", config.getQueryString());
config.setQueryTree(JexlASTHelper.parseAndFlattenJexlQuery("A == B"));
assertEquals("A == B", config.getQueryString());
config.setQueryTree(JexlASTHelper.parseAndFlattenJexlQuery("B == B"));
assertEquals("B == B", config.getQueryString());
}
use of datawave.query.config.ShardQueryConfiguration in project datawave by NationalSecurityAgency.
the class ShardQueryLogic method setupQuery.
@Override
public void setupQuery(GenericQueryConfiguration genericConfig) throws Exception {
if (!ShardQueryConfiguration.class.isAssignableFrom(genericConfig.getClass())) {
throw new QueryException("Did not receive a ShardQueryConfiguration instance!!");
}
ShardQueryConfiguration config = (ShardQueryConfiguration) genericConfig;
final QueryStopwatch timers = config.getTimers();
TraceStopwatch stopwatch = timers.newStartedStopwatch("ShardQueryLogic - Setup Query");
// Ensure we have all of the information needed to run a query
if (!config.canRunQuery()) {
log.warn("The given query '" + config + "' could not be run, most likely due to not matching any records in the global index.");
// Stub out an iterator to correctly present "no results"
this.iterator = new Iterator<Map.Entry<Key, Value>>() {
@Override
public boolean hasNext() {
return false;
}
@Override
public Map.Entry<Key, Value> next() {
return null;
}
@Override
public void remove() {
return;
}
};
this.scanner = null;
stopwatch.stop();
log.info(getStopwatchHeader(config));
List<String> timings = timers.summarizeAsList();
for (String timing : timings) {
log.info(timing);
}
return;
}
// Instantiate the scheduler for the queries
this.scheduler = getScheduler(config, scannerFactory);
this.scanner = null;
this.iterator = this.scheduler.iterator();
if (!config.isSortedUIDs()) {
this.iterator = new DedupingIterator(this.iterator);
}
stopwatch.stop();
log.info(getStopwatchHeader(config));
List<String> timings = timers.summarizeAsList();
for (String timing : timings) {
log.info(timing);
}
}
use of datawave.query.config.ShardQueryConfiguration in project datawave by NationalSecurityAgency.
the class DefaultQueryPlanner method initializeRangeStream.
/**
* Initializes the range stream, whether it is configured to be a different class than the Default Range stream or not.
*
* @param config
* @param scannerFactory
* @param metadataHelper
* @return
*/
private RangeStream initializeRangeStream(ShardQueryConfiguration config, ScannerFactory scannerFactory, MetadataHelper metadataHelper) {
Class<? extends RangeStream> rstream;
try {
rstream = Class.forName(rangeStreamClass).asSubclass(RangeStream.class);
RangeStream stream = rstream.getConstructor(ShardQueryConfiguration.class, ScannerFactory.class, MetadataHelper.class).newInstance(config, scannerFactory, metadataHelper);
return stream.setUidIntersector(uidIntersector).setLimitScanners(limitScanners).setCreateUidsIteratorClass(createUidsIteratorClass);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new RuntimeException(e);
}
}
use of datawave.query.config.ShardQueryConfiguration in project datawave by NationalSecurityAgency.
the class DefaultQueryPlanner method process.
@Override
public CloseableIterable<QueryData> process(GenericQueryConfiguration genericConfig, String query, Query settings, ScannerFactory scannerFactory) throws DatawaveQueryException {
if (!(genericConfig instanceof ShardQueryConfiguration)) {
throw new ClassCastException("Config object must be an instance of ShardQueryConfiguration");
}
builderThread = Executors.newSingleThreadExecutor();
ShardQueryConfiguration config = (ShardQueryConfiguration) genericConfig;
// lets mark the query as started (used by ivarators at a minimum)
try {
markQueryStarted(config, settings);
} catch (Exception e) {
throw new DatawaveQueryException("Failed to mark query as started" + settings.getId(), e);
}
return process(scannerFactory, getMetadataHelper(config), getDateIndexHelper(config), config, query, settings);
}
use of datawave.query.config.ShardQueryConfiguration in project datawave by NationalSecurityAgency.
the class CompositeIndexTest method getQueryRangesIterator.
private Iterator getQueryRangesIterator(String queryString, ShardQueryLogic logic) throws Exception {
MultivaluedMap<String, String> params = new MultivaluedMapImpl<>();
params.putSingle(QUERY_STRING, queryString);
params.putSingle(QUERY_NAME, "geoQuery");
params.putSingle(QUERY_LOGIC_NAME, "EventQueryLogic");
params.putSingle(QUERY_PERSISTENCE, "PERSISTENT");
params.putSingle(QUERY_AUTHORIZATIONS, AUTHS);
params.putSingle(QUERY_EXPIRATION, "20200101 000000.000");
params.putSingle(QUERY_BEGIN, BEGIN_DATE);
params.putSingle(QUERY_END, END_DATE);
QueryParameters queryParams = new QueryParametersImpl();
queryParams.validate(params);
Set<Authorizations> auths = new HashSet<>();
auths.add(new Authorizations(AUTHS));
Query query = new QueryImpl();
query.initialize(USER, Arrays.asList(USER_DN), null, queryParams, null);
ShardQueryConfiguration config = ShardQueryConfiguration.create(logic, query);
logic.initialize(config, instance.getConnector("root", PASSWORD), query, auths);
logic.setupQuery(config);
return config.getQueries();
}
Aggregations