Search in sources :

Example 1 with SpreadsheetSQLVisitor

use of org.teiid.translator.google.visitor.SpreadsheetSQLVisitor in project teiid by teiid.

the class TestSQLtoSpreadsheetQuery method testConversion.

private void testConversion(String sql, String expectedSpreadsheetQuery) throws Exception {
    Select select = (Select) getCommand(sql);
    SpreadsheetSQLVisitor spreadsheetVisitor = new SpreadsheetSQLVisitor(people);
    spreadsheetVisitor.translateSQL(select);
    assertEquals(expectedSpreadsheetQuery, spreadsheetVisitor.getTranslatedSQL());
}
Also used : SpreadsheetSQLVisitor(org.teiid.translator.google.visitor.SpreadsheetSQLVisitor) Select(org.teiid.language.Select)

Example 2 with SpreadsheetSQLVisitor

use of org.teiid.translator.google.visitor.SpreadsheetSQLVisitor in project teiid by teiid.

the class TestSQLtoSpreadsheetQuery method getVisitorAndTranslateSQL.

private SpreadsheetSQLVisitor getVisitorAndTranslateSQL(String sql) throws Exception {
    Select select = (Select) getCommand(sql);
    SpreadsheetSQLVisitor spreadsheetVisitor = new SpreadsheetSQLVisitor(people);
    spreadsheetVisitor.translateSQL(select);
    return spreadsheetVisitor;
}
Also used : SpreadsheetSQLVisitor(org.teiid.translator.google.visitor.SpreadsheetSQLVisitor) Select(org.teiid.language.Select)

Example 3 with SpreadsheetSQLVisitor

use of org.teiid.translator.google.visitor.SpreadsheetSQLVisitor in project teiid by teiid.

the class DirectSpreadsheetQueryExecution method execute.

@Override
public void execute() throws TranslatorException {
    String worksheet = null;
    Integer limit = null;
    Integer offset = null;
    String toQuery = query;
    List<String> parts = StringUtil.tokenize(query, ';');
    for (String var : parts) {
        int index = var.indexOf('=');
        if (index == -1) {
            continue;
        }
        String key = var.substring(0, index).trim();
        String value = var.substring(index + 1).trim();
        if (key.equalsIgnoreCase(WORKSHEET)) {
            worksheet = value;
        } else if (key.equalsIgnoreCase(QUERY)) {
            StringBuilder buffer = new StringBuilder();
            SQLStringVisitor.parseNativeQueryParts(value, arguments, buffer, new SQLStringVisitor.Substitutor() {

                @Override
                public void substitute(Argument arg, StringBuilder builder, int index) {
                    Literal argumentValue = arg.getArgumentValue();
                    SpreadsheetSQLVisitor visitor = new SpreadsheetSQLVisitor(connection.getSpreadsheetInfo());
                    visitor.visit(argumentValue);
                    builder.append(visitor.getTranslatedSQL());
                }
            });
            toQuery = buffer.toString();
        } else if (key.equalsIgnoreCase(LIMIT)) {
            limit = Integer.parseInt(value);
        } else if (key.equalsIgnoreCase(OFFEST)) {
            offset = Integer.parseInt(value);
        }
    }
    this.rowIterator = this.connection.executeQuery(worksheet, toQuery, offset, limit, executionContext.getBatchSize()).iterator();
}
Also used : Argument(org.teiid.language.Argument) SpreadsheetSQLVisitor(org.teiid.translator.google.visitor.SpreadsheetSQLVisitor) Literal(org.teiid.language.Literal)

Example 4 with SpreadsheetSQLVisitor

use of org.teiid.translator.google.visitor.SpreadsheetSQLVisitor in project teiid by teiid.

the class TestSQLtoSpreadsheetQuery method helpTestExpression.

private void helpTestExpression(String expression, String expected) throws QueryParserException {
    LanguageBridgeFactory lbf = new LanguageBridgeFactory(RealMetadataFactory.example1Cached());
    Expression ex = lbf.translate(QueryParser.getQueryParser().parseExpression(expression));
    SpreadsheetSQLVisitor spreadsheetVisitor = new SpreadsheetSQLVisitor(people);
    spreadsheetVisitor.translateSQL(ex);
    assertEquals(expected, spreadsheetVisitor.getTranslatedSQL());
}
Also used : Expression(org.teiid.language.Expression) SpreadsheetSQLVisitor(org.teiid.translator.google.visitor.SpreadsheetSQLVisitor) LanguageBridgeFactory(org.teiid.dqp.internal.datamgr.LanguageBridgeFactory)

Example 5 with SpreadsheetSQLVisitor

use of org.teiid.translator.google.visitor.SpreadsheetSQLVisitor in project teiid by teiid.

the class TestSQLtoSpreadsheetQuery method testSelectVisitorValues.

@Test
public void testSelectVisitorValues() throws Exception {
    SpreadsheetSQLVisitor visitor = getVisitorAndTranslateSQL("select * from PeopleList where A = 'car' limit 2");
    testVisitorValues(visitor, "PeopleList", 2, null);
    visitor = getVisitorAndTranslateSQL("select * from PeopleList where A = 'car' offset 5 row");
    testVisitorValues(visitor, "PeopleList", Integer.MAX_VALUE, 5);
    visitor = getVisitorAndTranslateSQL("select A,B from PeopleList where B like 'Filip%' order by B desc");
    testVisitorValues(visitor, "PeopleList", null, null);
    visitor = getVisitorAndTranslateSQL("select A,B from PeopleList limit 2,3");
    testVisitorValues(visitor, "PeopleList", 3, 2);
}
Also used : SpreadsheetSQLVisitor(org.teiid.translator.google.visitor.SpreadsheetSQLVisitor) Test(org.junit.Test)

Aggregations

SpreadsheetSQLVisitor (org.teiid.translator.google.visitor.SpreadsheetSQLVisitor)6 Select (org.teiid.language.Select)2 Test (org.junit.Test)1 LanguageBridgeFactory (org.teiid.dqp.internal.datamgr.LanguageBridgeFactory)1 Argument (org.teiid.language.Argument)1 Expression (org.teiid.language.Expression)1 Literal (org.teiid.language.Literal)1