use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class TestDynamicCommand method testClone1.
public void testClone1() {
List symbols = new ArrayList();
// $NON-NLS-1$
ElementSymbol a1 = new ElementSymbol("a1");
a1.setType(DataTypeManager.DefaultDataClasses.STRING);
symbols.add(a1);
DynamicCommand sqlCmd = new DynamicCommand();
// $NON-NLS-1$
Expression sql = new Constant("SELECT a1 FROM g WHERE a2 = 5");
sqlCmd.setSql(sql);
sqlCmd.setAsColumns(symbols);
sqlCmd.setAsClauseSet(true);
// $NON-NLS-1$
sqlCmd.setIntoGroup(new GroupSymbol("#g"));
UnitTestUtil.helpTestEquivalence(0, sqlCmd, sqlCmd.clone());
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class TestDynamicCommand method testClone2.
public void testClone2() {
List symbols = new ArrayList();
// $NON-NLS-1$
ElementSymbol a1 = new ElementSymbol("a1");
a1.setType(DataTypeManager.DefaultDataClasses.STRING);
symbols.add(a1);
// $NON-NLS-1$
Expression sql = new Constant("SELECT * FROM g");
SetClauseList using = new SetClauseList();
using.addClause(a1, a1);
// $NON-NLS-1$
DynamicCommand sqlCmd = new DynamicCommand(sql, symbols, new GroupSymbol("#g"), using);
UnitTestUtil.helpTestEquivalence(0, sqlCmd, sqlCmd.clone());
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class RequestWorkItem method createResultsMessage.
public ResultsMessage createResultsMessage(List<? extends List<?>> batch, List<? extends Expression> columnSymbols) {
String[] columnNames = new String[columnSymbols.size()];
String[] dataTypes = new String[columnSymbols.size()];
byte clientSerializationVersion = this.dqpWorkContext.getClientVersion().getClientSerializationVersion();
for (int i = 0; i < columnSymbols.size(); i++) {
Expression symbol = columnSymbols.get(i);
columnNames[i] = Symbol.getShortName(Symbol.getOutputName(symbol));
dataTypes[i] = DataTypeManager.getDataTypeName(symbol.getType());
if (dataTypes[i].equals(DataTypeManager.DefaultDataTypes.GEOMETRY) && !this.dqpWorkContext.getSession().isEmbedded() && clientSerializationVersion < BatchSerializer.VERSION_GEOMETRY) {
dataTypes[i] = DataTypeManager.DefaultDataTypes.BLOB;
}
}
ResultsMessage result = new ResultsMessage(batch, columnNames, dataTypes);
result.setClientSerializationVersion(clientSerializationVersion);
result.setDelayDeserialization(this.requestMsg.isDelaySerialization() && this.originalCommand.returnsResultSet());
return result;
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class DefaultAuthorizationValidator method validate.
@Override
public boolean validate(String[] originalSql, Command command, QueryMetadataInterface metadata, CommandContext commandContext, CommandType commandType) throws QueryValidatorException, TeiidComponentException {
boolean modified = false;
if (policyDecider != null && policyDecider.validateCommand(commandContext)) {
if (ignoreUnathorizedInAsterisk(command, commandContext)) {
Query query = (Query) command;
HashMap<String, LanguageObject> map = null;
for (Expression ex : query.getSelect().getSymbols()) {
if (ex instanceof MultipleElementSymbol) {
MultipleElementSymbol mes = (MultipleElementSymbol) ex;
if (map == null) {
map = new HashMap<String, LanguageObject>();
}
for (Iterator<ElementSymbol> iter = mes.getElementSymbols().iterator(); iter.hasNext(); ) {
ElementSymbol es = iter.next();
Object metadataObject = es.getMetadataID();
if (metadataObject instanceof MultiSourceElement || metadataObject instanceof TempMetadataID) {
continue;
}
map.clear();
AuthorizationValidationVisitor.addToNameMap(metadataObject, es, map, commandContext.getMetadata());
Set<String> results = this.policyDecider.getInaccessibleResources(PermissionType.READ, map.keySet(), Context.QUERY, commandContext);
if (!results.isEmpty()) {
// remove from the select
iter.remove();
modified = true;
}
}
}
}
if (query.getProjectedSymbols().isEmpty()) {
throw new QueryValidatorException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31151));
}
}
AuthorizationValidationVisitor visitor = new AuthorizationValidationVisitor(this.policyDecider, commandContext);
Request.validateWithVisitor(visitor, metadata, command);
}
return modified;
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class MetaDataProcessor method getMetadataForCommand.
// For each projected symbol, construct a metadata map
private MetadataResult getMetadataForCommand(Command originalCommand) throws TeiidComponentException {
Map<Integer, Object>[] columnMetadata = null;
switch(originalCommand.getType()) {
case Command.TYPE_QUERY:
if (originalCommand instanceof Query) {
if (((Query) originalCommand).getInto() == null) {
columnMetadata = createProjectedSymbolMetadata(originalCommand);
}
} else {
columnMetadata = createProjectedSymbolMetadata(originalCommand);
}
break;
case Command.TYPE_STORED_PROCEDURE:
columnMetadata = createProjectedSymbolMetadata(originalCommand);
break;
case Command.TYPE_INSERT:
case Command.TYPE_UPDATE:
case Command.TYPE_DELETE:
case Command.TYPE_CREATE:
case Command.TYPE_DROP:
break;
default:
if (originalCommand.returnsResultSet()) {
columnMetadata = createProjectedSymbolMetadata(originalCommand);
}
}
Map<Reference, String> paramMap = Collections.emptyMap();
if (originalCommand instanceof StoredProcedure) {
StoredProcedure sp = (StoredProcedure) originalCommand;
paramMap = new HashMap<Reference, String>();
Collection<SPParameter> params = sp.getParameters();
for (SPParameter spParameter : params) {
if (spParameter.getParameterType() != SPParameter.INOUT && spParameter.getParameterType() != SPParameter.IN && spParameter.getParameterType() != SPParameter.RETURN_VALUE) {
continue;
}
Expression ex = spParameter.getExpression();
if (ex instanceof Function && FunctionLibrary.isConvert((Function) ex)) {
ex = ((Function) ex).getArg(0);
}
if (ex instanceof Reference) {
paramMap.put((Reference) ex, spParameter.getParameterSymbol().getShortName());
}
}
}
List<Reference> params = ReferenceCollectorVisitor.getReferences(originalCommand);
Map<Integer, Object>[] paramMetadata = new Map[params.size()];
for (int i = 0; i < params.size(); i++) {
Reference param = params.get(i);
paramMetadata[i] = getDefaultColumn(null, paramMap.get(param), param.getType());
}
return new MetadataResult(columnMetadata, paramMetadata);
}
Aggregations