use of org.teiid.api.exception.query.QueryValidatorException in project teiid by teiid.
the class ValidationVisitor method visit.
@Override
public void visit(AlterProcedure obj) {
GroupSymbol gs = obj.getTarget();
validateAlterTarget(obj);
try {
if (!gs.isProcedure() || !getMetadata().isVirtualModel(getMetadata().getModelID(gs.getMetadataID()))) {
// $NON-NLS-1$
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.not_a_procedure", gs), gs);
return;
}
Validator.validate(obj.getDefinition(), getMetadata(), this);
StoredProcedureInfo info = getMetadata().getStoredProcedureInfoForProcedure(gs.getName());
for (SPParameter param : info.getParameters()) {
if (param.getParameterType() == SPParameter.RESULT_SET) {
QueryResolver.validateProjectedSymbols(gs, param.getResultSetColumns(), obj.getDefinition().getProjectedSymbols());
break;
}
}
} catch (QueryValidatorException e) {
handleValidationError(e.getMessage(), obj.getDefinition().getBlock());
} catch (TeiidComponentException e) {
handleException(e);
}
}
use of org.teiid.api.exception.query.QueryValidatorException in project teiid by teiid.
the class TestAuthorizationValidationVisitor method testPruneSelectAll.
@Test
public void testPruneSelectAll() throws Exception {
String sql = "select * from pm1.g1";
QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
DataPolicyMetadata svc = new DataPolicyMetadata();
// $NON-NLS-1$
svc.setName("test");
// $NON-NLS-1$
svc.addPermission(addResource(DataPolicy.PermissionType.READ, "pm1"));
PermissionMetaData p = addResource(DataPolicy.PermissionType.READ, "pm1.g1.e1");
p.setAllowRead(false);
// $NON-NLS-1$
svc.addPermission(p);
DataRolePolicyDecider dataRolePolicyDecider = createPolicyDecider(metadata, RealMetadataFactory.example1VDB(), svc);
DefaultAuthorizationValidator dav = new DefaultAuthorizationValidator();
dav.setPolicyDecider(dataRolePolicyDecider);
this.context.setSessionVariable(DefaultAuthorizationValidator.IGNORE_UNAUTHORIZED_ASTERISK, "true");
QueryParser parser = QueryParser.getQueryParser();
Command command = parser.parseCommand(sql);
QueryResolver.resolveCommand(command, metadata);
assertEquals(4, command.getProjectedSymbols().size());
boolean modified = dav.validate(new String[] {}, command, metadata, this.context, CommandType.USER);
assertTrue(modified);
assertEquals(3, command.getProjectedSymbols().size());
p = addResource(DataPolicy.PermissionType.READ, "pm1.g1");
p.setAllowRead(false);
// $NON-NLS-1$
svc.addPermission(p);
command = parser.parseCommand(sql);
QueryResolver.resolveCommand(command, metadata);
assertEquals(4, command.getProjectedSymbols().size());
try {
dav.validate(new String[] {}, command, metadata, this.context, CommandType.USER);
fail();
} catch (QueryValidatorException e) {
}
}
use of org.teiid.api.exception.query.QueryValidatorException in project teiid by teiid.
the class TestProcedurePlanner method helpPlanProcedure.
// ################ getReplacementClause tests ###################
private ProcessorPlan helpPlanProcedure(String userQuery, String procedure, TriggerEvent procedureType) throws TeiidComponentException, QueryMetadataException, TeiidProcessingException {
QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(procedureType, procedure);
QueryParser parser = QueryParser.getQueryParser();
Command userCommand = userQuery != null ? parser.parseCommand(userQuery) : parser.parseCommand(procedure);
if (userCommand instanceof CreateProcedureCommand) {
GroupSymbol gs = new GroupSymbol("proc");
gs.setMetadataID(new TempMetadataID("proc", Collections.EMPTY_LIST));
((CreateProcedureCommand) userCommand).setVirtualGroup(gs);
}
QueryResolver.resolveCommand(userCommand, metadata);
ValidatorReport report = Validator.validate(userCommand, metadata);
if (report.hasItems()) {
ValidatorFailure firstFailure = report.getItems().iterator().next();
throw new QueryValidatorException(firstFailure.getMessage());
}
userCommand = QueryRewriter.rewrite(userCommand, metadata, null);
AnalysisRecord analysisRecord = new AnalysisRecord(false, DEBUG);
try {
return QueryOptimizer.optimizePlan(userCommand, metadata, null, new DefaultCapabilitiesFinder(), analysisRecord, null);
} finally {
if (DEBUG) {
System.out.println(analysisRecord.getDebugLog());
}
}
}
use of org.teiid.api.exception.query.QueryValidatorException in project teiid by teiid.
the class TestGlobalTemp method testGlobalTempUse.
@Test
public void testGlobalTempUse() throws Exception {
TempTableTestHarness harness = new TempTableTestHarness();
TransformationMetadata metadata = RealMetadataFactory.fromDDL("create global temporary table temp (x serial, s string) options (updatable true);" + "", "x", "y");
HardcodedDataManager dm = new HardcodedDataManager();
harness.setUp(metadata, dm);
harness.execute("select * from temp", new List<?>[0]);
harness.execute("insert into temp (s) values ('a')", new List<?>[] { Arrays.asList(1) });
harness.execute("select * from temp", new List<?>[] { Arrays.asList(1, "a") });
try {
harness.execute("drop table temp", new List<?>[0]);
fail();
} catch (QueryValidatorException e) {
}
}
use of org.teiid.api.exception.query.QueryValidatorException in project teiid by teiid.
the class TestProcedureProcessor method getProcedurePlan.
public static ProcessorPlan getProcedurePlan(String userQuery, QueryMetadataInterface metadata, CapabilitiesFinder capabilitiesFinder) throws Exception {
Command userCommand = QueryParser.getQueryParser().parseCommand(userQuery);
QueryResolver.resolveCommand(userCommand, metadata);
ValidatorReport report = Validator.validate(userCommand, metadata);
if (report.hasItems()) {
ValidatorFailure firstFailure = report.getItems().iterator().next();
throw new QueryValidatorException(firstFailure.getMessage());
}
QueryRewriter.rewrite(userCommand, metadata, new CommandContext());
AnalysisRecord analysisRecord = new AnalysisRecord(false, DEBUG);
try {
if (capabilitiesFinder == null) {
capabilitiesFinder = new DefaultCapabilitiesFinder();
}
ProcessorPlan plan = QueryOptimizer.optimizePlan(userCommand, metadata, null, capabilitiesFinder, analysisRecord, null);
return plan;
} finally {
if (DEBUG) {
System.out.println(analysisRecord.getDebugLog());
}
}
}
Aggregations