
prerna.reactor.qs.source.DatabaseReactor Maven / Gradle / Ivy
The newest version!
package prerna.reactor.qs.source;
import prerna.auth.utils.SecurityEngineUtils;
import prerna.auth.utils.SecurityQueryUtils;
import prerna.query.querystruct.AbstractQueryStruct;
import prerna.query.querystruct.SelectQueryStruct;
import prerna.reactor.EmbeddedRoutineReactor;
import prerna.reactor.EmbeddedScriptReactor;
import prerna.reactor.GenericReactor;
import prerna.reactor.qs.AbstractQueryStructReactor;
import prerna.sablecc2.om.GenRowStruct;
import prerna.sablecc2.om.PixelDataType;
import prerna.sablecc2.om.ReactorKeysEnum;
import prerna.sablecc2.om.nounmeta.NounMetadata;
import prerna.util.Constants;
import prerna.util.DIHelper;
import prerna.util.Utility;
public class DatabaseReactor extends AbstractQueryStructReactor {
public DatabaseReactor() {
this.keysToGet = new String[]{ReactorKeysEnum.DATABASE.getKey()};
}
@Override
protected AbstractQueryStruct createQueryStruct() {
// get the selectors
this.organizeKeys();
String databaseId = this.keyValue.get(this.keysToGet[0]);
// we may have the alias
databaseId = SecurityQueryUtils.testUserEngineIdForAlias(this.insight.getUser(), databaseId);
if(!SecurityEngineUtils.userCanViewEngine(this.insight.getUser(), databaseId)) {
throw new IllegalArgumentException("Database " + databaseId + " does not exist or user does not have access to database");
}
this.qs.setEngineId(databaseId);
// add the engine to the insight
this.insight.addQueriedDatabasesese(databaseId);
//checking if it is a big data engine
String smssFile = (String) DIHelper.getInstance().getEngineProperty(databaseId + "_" + Constants.STORE);
Object bigDataProp = Utility.loadProperties(smssFile).get(Constants.BIG_DATA_ENGINE);
if(bigDataProp!= null){
if(Boolean.parseBoolean(bigDataProp.toString())){
this.qs.setBigDataEngine(true);
}
}
// need to account if this is a hard query struct
if(this.qs.getQsType() == SelectQueryStruct.QUERY_STRUCT_TYPE.RAW_ENGINE_QUERY ||
this.qs.getQsType() == SelectQueryStruct.QUERY_STRUCT_TYPE.RAW_FRAME_QUERY) {
this.qs.setQsType(SelectQueryStruct.QUERY_STRUCT_TYPE.RAW_ENGINE_QUERY);
} else {
this.qs.setQsType(SelectQueryStruct.QUERY_STRUCT_TYPE.ENGINE);
}
return this.qs;
}
@Override
public void mergeUp() {
// merge this reactor into the parent reactor
init();
createQueryStructPlan();
if(parentReactor != null) {
// this is only called lazy
// have to init to set the qs
// to them add to the parent
NounMetadata data = new NounMetadata(this.qs, PixelDataType.QUERY_STRUCT);
if(parentReactor instanceof EmbeddedScriptReactor || parentReactor instanceof EmbeddedRoutineReactor
|| parentReactor instanceof GenericReactor) {
parentReactor.getCurRow().add(data);
} else {
GenRowStruct parentQSInput = parentReactor.getNounStore().makeNoun(PixelDataType.QUERY_STRUCT.toString());
parentQSInput.add(data);
}
}
}
private AbstractQueryStruct createQueryStructPlan() {
this.organizeKeys();
String engineId = this.keyValue.get(this.keysToGet[0]);
this.qs.setEngineId(engineId);
// need to account if this is a hard query struct
if(this.qs.getQsType() == SelectQueryStruct.QUERY_STRUCT_TYPE.RAW_ENGINE_QUERY ||
this.qs.getQsType() == SelectQueryStruct.QUERY_STRUCT_TYPE.RAW_FRAME_QUERY) {
this.qs.setQsType(SelectQueryStruct.QUERY_STRUCT_TYPE.RAW_ENGINE_QUERY);
} else {
this.qs.setQsType(SelectQueryStruct.QUERY_STRUCT_TYPE.ENGINE);
}
return this.qs;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy