Search in sources :

Example 26 with LanguageObject

use of org.teiid.query.sql.LanguageObject in project teiid by teiid.

the class TestBatchedUpdatePlanner method helpGetCommands.

public static List<Command> helpGetCommands(String[] sql, QueryMetadataInterface md) throws TeiidComponentException, TeiidProcessingException {
    // $NON-NLS-1$
    if (DEBUG)
        System.out.println("\n####################################\n" + sql);
    List<Command> commands = new ArrayList<Command>(sql.length);
    for (int i = 0; i < sql.length; i++) {
        Command command = QueryParser.getQueryParser().parseCommand(sql[i]);
        QueryResolver.resolveCommand(command, md);
        ValidatorReport repo = Validator.validate(command, md);
        Collection<LanguageObject> failures = new ArrayList<LanguageObject>();
        repo.collectInvalidObjects(failures);
        if (failures.size() > 0) {
            // $NON-NLS-1$
            fail("Exception during validation (" + repo);
        }
        command = QueryRewriter.rewrite(command, md, null);
        commands.add(command);
    }
    return commands;
}
Also used : Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) ArrayList(java.util.ArrayList) ValidatorReport(org.teiid.query.validator.ValidatorReport) LanguageObject(org.teiid.query.sql.LanguageObject)

Example 27 with LanguageObject

use of org.teiid.query.sql.LanguageObject in project teiid by teiid.

the class TestDeepGroupCollectorVisitor method helpTestVisitor.

public void helpTestVisitor(String sql, String[] expectedGroups) {
    LanguageObject obj = null;
    try {
        obj = QueryParser.getQueryParser().parseCommand(sql);
    } catch (TeiidException e) {
        throw new RuntimeException(e);
    }
    Collection actualGroups = GroupCollectorVisitor.getGroupsIgnoreInlineViews(obj, false);
    // $NON-NLS-1$
    assertEquals("Did not get expected number of groups", expectedGroups.length, actualGroups.size());
    Iterator iter = actualGroups.iterator();
    for (int i = 0; iter.hasNext(); i++) {
        GroupSymbol group = (GroupSymbol) iter.next();
        assertTrue(// $NON-NLS-1$ //$NON-NLS-2$
        "Expected group did not match, expected=" + expectedGroups[i] + ", actual=" + group, group.getName().equalsIgnoreCase(expectedGroups[i]));
    }
}
Also used : Iterator(java.util.Iterator) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) Collection(java.util.Collection) LanguageObject(org.teiid.query.sql.LanguageObject) TeiidException(org.teiid.core.TeiidException)

Example 28 with LanguageObject

use of org.teiid.query.sql.LanguageObject in project teiid by teiid.

the class TestValidator method examineReport.

private static void examineReport(Object command, String[] expectedStringArray, ValidatorReport report) {
    // Get invalid objects from report
    Collection<LanguageObject> actualObjs = new ArrayList<LanguageObject>();
    report.collectInvalidObjects(actualObjs);
    // Compare expected and actual objects
    Set<String> expectedStrings = new HashSet<String>(Arrays.asList(expectedStringArray));
    Set<String> actualStrings = new HashSet<String>();
    for (LanguageObject obj : actualObjs) {
        actualStrings.add(SQLStringVisitor.getSQLString(obj));
    }
    if (expectedStrings.size() == 0 && actualStrings.size() > 0) {
        // $NON-NLS-1$
        fail("Expected no failures but got some: " + report.getFailureMessage());
    } else if (actualStrings.size() == 0 && expectedStrings.size() > 0) {
        // $NON-NLS-1$
        fail("Expected some failures but got none for sql = " + command);
    } else {
        // $NON-NLS-1$
        assertEquals("Expected and actual sets of strings are not the same: ", expectedStrings, actualStrings);
    }
}
Also used : ArrayList(java.util.ArrayList) LanguageObject(org.teiid.query.sql.LanguageObject) HashSet(java.util.HashSet)

Aggregations

LanguageObject (org.teiid.query.sql.LanguageObject)28 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)8 TeiidComponentException (org.teiid.core.TeiidComponentException)7 ArrayList (java.util.ArrayList)5 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)5 HashSet (java.util.HashSet)3 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)3 Command (org.teiid.query.sql.lang.Command)3 Criteria (org.teiid.query.sql.lang.Criteria)3 Select (org.teiid.query.sql.lang.Select)3 Expression (org.teiid.query.sql.symbol.Expression)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Test (org.junit.Test)2 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)2 MultiSourceElement (org.teiid.dqp.internal.process.multisource.MultiSourceElement)2 TempMetadataID (org.teiid.query.metadata.TempMetadataID)2 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)2 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)2