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());
}
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;
}
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();
}
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());
}
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);
}
Aggregations