use of org.teiid.query.parser.QueryParser in project teiid by teiid.
the class MaterializationMetadataRepository method fixScript.
/**
* Rather than require a script to be tokenized directly
* we expect it to be wrapped in an anon block
* @param property
* @param table
* @return
*/
private String fixScript(String property, Table table) {
String script = table.getProperty(property, false);
if (script == null) {
return null;
}
if (!script.contains(";")) {
// $NON-NLS-1$
return script;
}
QueryParser parser = QueryParser.getQueryParser();
try {
parser.parseCommand(script);
return script;
} catch (QueryParserException e) {
}
// $NON-NLS-1$ //$NON-NLS-2$
String wrapped = "begin " + script + "; end";
try {
parser.parseCommand(wrapped);
table.setProperty(property, wrapped);
return wrapped;
} catch (QueryParserException e) {
}
// because we don't handle empty ; in scripts also try without
// $NON-NLS-1$ //$NON-NLS-2$
wrapped = "begin " + script + " end";
try {
parser.parseCommand(wrapped);
table.setProperty(property, wrapped);
return wrapped;
} catch (QueryParserException e) {
}
// give up
return script;
}
use of org.teiid.query.parser.QueryParser in project teiid by teiid.
the class ProcedureContainerResolver method expandCommand.
/**
* Expand a command by finding and attaching all subcommands to the command. If
* some initial resolution must be done for this to be accomplished, that is ok,
* but it should be kept to a minimum.
* @param command The command to expand
* @param useMetadataCommands True if resolver should use metadata commands to completely resolve
* @param metadata Metadata access
* @param analysis The analysis record that will be filled in if doing annotation.
*
* @throws QueryMetadataException If there is a metadata problem
* @throws QueryResolverException If the query cannot be resolved
* @throws TeiidComponentException If there is an internal error
*/
public Command expandCommand(ProcedureContainer procCommand, QueryMetadataInterface metadata, AnalysisRecord analysis) throws QueryMetadataException, QueryResolverException, TeiidComponentException {
// Resolve group so we can tell whether it is an update procedure
GroupSymbol group = procCommand.getGroup();
Command subCommand = null;
String plan = getPlan(metadata, procCommand);
if (plan == null) {
return null;
}
QueryParser parser = QueryParser.getQueryParser();
try {
subCommand = parser.parseProcedure(plan, !(procCommand instanceof StoredProcedure));
} catch (QueryParserException e) {
throw new QueryResolverException(QueryPlugin.Event.TEIID30060, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30060, group, procCommand.getClass().getSimpleName()));
}
return subCommand;
}
use of org.teiid.query.parser.QueryParser 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.query.parser.QueryParser in project teiid by teiid.
the class TestSchemaToProtobufProcessor method testSimpleNoMetadataConversion.
@Test
public void testSimpleNoMetadataConversion() throws Exception {
Properties props = new Properties();
MetadataFactory mf = new MetadataFactory("proto", 1, "model", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
mf.setParser(new QueryParser());
mf.parse(new FileReader(UnitTestUtil.getTestDataFile("tables_no_metadata.ddl")));
SchemaToProtobufProcessor tool = new SchemaToProtobufProcessor();
tool.setIndexMessages(true);
InfinispanConnection conn = Mockito.mock(InfinispanConnection.class);
BasicCache cache = Mockito.mock(BasicCache.class);
Mockito.stub(cache.getName()).toReturn("default");
Mockito.stub(conn.getCache()).toReturn(cache);
ProtobufResource resource = tool.process(mf, conn);
String expected = "package model;\n" + "\n" + "/* @Indexed */\n" + "message G1 {\n" + " /* @Id */\n" + " required int32 e1 = 1;\n" + " required string e2 = 2;\n" + " optional float e3 = 3;\n" + " repeated string e4 = 4;\n" + " repeated string e5 = 5;\n" + "}\n" + "\n" + "/* @Indexed */\n" + "message G2 {\n" + " /* @Id */\n" + " required int32 e1 = 1;\n" + " optional string e2 = 2;\n" + " optional bytes e5 = 3;\n" + " optional int64 e6 = 4;\n" + " repeated G4 g4 = 5;\n" + "}\n" + "\n" + "/* @Indexed */\n" + "message G4 {\n" + " required int32 e1 = 1;\n" + " required string e2 = 2;\n" + " optional double e3 = 3;\n" + " optional float e4 = 4;\n" + " /* @Teiid(type=short) */\n" + " optional int32 e5 = 5;\n" + " /* @Teiid(type=byte) */\n" + " optional int32 e6 = 6;\n" + " /* @Teiid(type=char, length=1) */\n" + " optional string e7 = 7;\n" + " optional int64 e8 = 8;\n" + " /* @Teiid(type=bigdecimal) */\n" + " optional string e9 = 9;\n" + " /* @Teiid(type=biginteger) */\n" + " optional string e10 = 10;\n" + " /* @Teiid(type=time) */\n" + " optional int64 e11 = 11;\n" + " /* @Teiid(type=timestamp) */\n" + " optional int64 e12 = 12;\n" + " /* @Teiid(type=date) */\n" + " optional int64 e13 = 13;\n" + " /* @Teiid(type=object) */\n" + " optional bytes e14 = 14;\n" + " /* @Teiid(type=blob) */\n" + " optional bytes e15 = 15;\n" + " /* @Teiid(type=clob) */\n" + " optional bytes e16 = 16;\n" + " /* @Teiid(type=xml) */\n" + " optional bytes e17 = 17;\n" + " /* @Teiid(type=geometry) */\n" + " optional bytes e18 = 18;\n" + "}\n\n";
assertEquals(expected, resource.getContents());
}
use of org.teiid.query.parser.QueryParser 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());
}
}
}
Aggregations