use of org.teiid.language.Literal in project teiid by teiid.
the class TestOracleTranslator method testArrayComparison.
@Test
public void testArrayComparison() throws Exception {
// $NON-NLS-1$
String input = "select intkey from bqt1.smalla where intkey = 5";
// $NON-NLS-1$
String output = "SELECT g_0.IntKey FROM SmallA g_0 WHERE (g_0.IntKey, g_0.IntKey) = ((5, 2))";
CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
Select obj = (Select) commandBuilder.getCommand(input, true, true);
Comparison comp = (Comparison) obj.getWhere();
// modify to an array comparison, since there is not yet parsing support
comp.setLeftExpression(new Array(comp.getLeftExpression().getType(), Arrays.asList(comp.getLeftExpression(), comp.getLeftExpression())));
comp.setRightExpression(new Array(comp.getLeftExpression().getType(), Arrays.asList(comp.getRightExpression(), new Literal(2, TypeFacility.RUNTIME_TYPES.INTEGER))));
TranslationHelper.helpTestVisitor(output, TRANSLATOR, obj);
}
use of org.teiid.language.Literal in project teiid by teiid.
the class TeradataSQLConversionVisitor method visit.
@Override
public void visit(In obj) {
List<Expression> exprs = obj.getRightExpressions();
boolean decompose = false;
for (Expression expr : exprs) {
if (!(expr instanceof Literal)) {
decompose = true;
break;
}
}
if (decompose) {
List<Expression> literals = new ArrayList<Expression>();
Comparison.Operator opCode = obj.isNegated() ? Comparison.Operator.NE : Comparison.Operator.EQ;
if (exprs.size() > 1) {
Condition left = null;
for (Expression expr : obj.getRightExpressions()) {
if (expr instanceof Literal) {
literals.add(expr);
} else {
if (left == null) {
left = LanguageFactory.INSTANCE.createCompareCriteria(opCode, obj.getLeftExpression(), expr);
} else {
left = LanguageFactory.INSTANCE.createAndOr(obj.isNegated() ? Operator.AND : Operator.OR, left, LanguageFactory.INSTANCE.createCompareCriteria(opCode, obj.getLeftExpression(), expr));
}
}
}
if (!literals.isEmpty()) {
left = LanguageFactory.INSTANCE.createAndOr(obj.isNegated() ? Operator.AND : Operator.OR, left, new In(obj.getLeftExpression(), literals, obj.isNegated()));
}
buffer.append(Tokens.LPAREN);
super.visit((AndOr) left);
buffer.append(Tokens.RPAREN);
} else {
super.visit(LanguageFactory.INSTANCE.createCompareCriteria(opCode, obj.getLeftExpression(), exprs.get(0)));
}
} else {
super.visit(obj);
}
}
use of org.teiid.language.Literal in project teiid by teiid.
the class TestEscapeSyntaxModifier method testEscape.
public void testEscape() {
// $NON-NLS-1$
Literal arg1 = CommandBuilder.getLanuageFactory().createLiteral("arg1", String.class);
// $NON-NLS-1$
Literal arg2 = CommandBuilder.getLanuageFactory().createLiteral("arg2", String.class);
// $NON-NLS-1$
Function func = CommandBuilder.getLanuageFactory().createFunction("concat", Arrays.asList(arg1, arg2), Integer.class);
helpTest(func, "{fn concat('arg1', 'arg2')}");
}
use of org.teiid.language.Literal in project teiid by teiid.
the class TestExtractFunctionModifier method test1.
public void test1() throws Exception {
Literal arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
// $NON-NLS-1$ //$NON-NLS-2$
helpTestMod(arg1, "EXTRACT(MONTH FROM {d '2004-01-21'})", "month");
}
use of org.teiid.language.Literal in project teiid by teiid.
the class TestExtractFunctionModifier method test3.
public void test3() throws Exception {
Literal arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createDate(104, 0, 21), java.sql.Date.class);
// $NON-NLS-1$ //$NON-NLS-2$
helpTestMod(arg1, "EXTRACT(YEAR FROM {d '2004-01-21'})", "year");
}
Aggregations