use of com.facebook.presto.expressions.translator.TranslatedExpression in project presto by prestodb.
the class TestRowExpressionTranslator method testUntranslatableSpecialForm.
@Test
public void testUntranslatableSpecialForm() {
String untranslated = "col1 OR col2";
TypeProvider typeProvider = TypeProvider.copyOf(ImmutableMap.of("col1", BOOLEAN, "col2", BOOLEAN));
RowExpression specialForm = sqlToRowExpressionTranslator.translate(expression(untranslated), typeProvider);
TranslatedExpression translatedExpression = translateWith(specialForm, new TestFunctionTranslator(functionAndTypeManager, buildFunctionTranslator(ImmutableSet.of(TestFunctions.class))), emptyMap());
assertFalse(translatedExpression.getTranslated().isPresent());
}
use of com.facebook.presto.expressions.translator.TranslatedExpression in project presto by prestodb.
the class TestRowExpressionTranslator method testBasicOperator.
@Test
public void testBasicOperator() {
String untranslated = "col1 + col2";
TypeProvider typeProvider = TypeProvider.copyOf(ImmutableMap.of("col1", BIGINT, "col2", BIGINT));
RowExpression specialForm = sqlToRowExpressionTranslator.translate(expression(untranslated), typeProvider);
TranslatedExpression translatedExpression = translateWith(specialForm, new TestFunctionTranslator(functionAndTypeManager, buildFunctionTranslator(ImmutableSet.of(TestFunctions.class))), emptyMap());
assertTrue(translatedExpression.getTranslated().isPresent());
assertEquals(translatedExpression.getTranslated().get(), "col1 -|- col2");
}
use of com.facebook.presto.expressions.translator.TranslatedExpression in project presto by prestodb.
the class TestRowExpressionTranslator method testEndToEndSpecialFormTranslation.
@Test
public void testEndToEndSpecialFormTranslation() {
String untranslated = "col1 AND col2";
TypeProvider typeProvider = TypeProvider.copyOf(ImmutableMap.of("col1", BOOLEAN, "col2", BOOLEAN));
RowExpression specialForm = sqlToRowExpressionTranslator.translate(expression(untranslated), typeProvider);
TranslatedExpression translatedExpression = translateWith(specialForm, new TestFunctionTranslator(functionAndTypeManager, buildFunctionTranslator(ImmutableSet.of(TestFunctions.class))), emptyMap());
assertTrue(translatedExpression.getTranslated().isPresent());
assertEquals(translatedExpression.getTranslated().get(), "col1 TEST_AND col2");
}
use of com.facebook.presto.expressions.translator.TranslatedExpression in project presto by prestodb.
the class JdbcFilterToSqlTranslator method translateVariable.
@Override
public TranslatedExpression<JdbcExpression> translateVariable(VariableReferenceExpression variable, Map<VariableReferenceExpression, ColumnHandle> context, RowExpressionTreeTranslator<JdbcExpression, Map<VariableReferenceExpression, ColumnHandle>> rowExpressionTreeTranslator) {
JdbcColumnHandle columnHandle = (JdbcColumnHandle) context.get(variable);
requireNonNull(columnHandle, format("Unrecognized variable %s", variable));
return new TranslatedExpression<>(Optional.of(new JdbcExpression(quote + columnHandle.getColumnName().replace(quote, quote + quote) + quote)), variable, ImmutableList.of());
}
use of com.facebook.presto.expressions.translator.TranslatedExpression in project presto by prestodb.
the class JdbcFilterToSqlTranslator method translateCall.
@Override
public TranslatedExpression<JdbcExpression> translateCall(CallExpression call, Map<VariableReferenceExpression, ColumnHandle> context, RowExpressionTreeTranslator<JdbcExpression, Map<VariableReferenceExpression, ColumnHandle>> rowExpressionTreeTranslator) {
List<TranslatedExpression<JdbcExpression>> translatedExpressions = call.getArguments().stream().map(expression -> rowExpressionTreeTranslator.rewrite(expression, context)).collect(toImmutableList());
FunctionMetadata functionMetadata = functionMetadataManager.getFunctionMetadata(call.getFunctionHandle());
try {
return functionTranslator.translate(functionMetadata, call, translatedExpressions);
} catch (Throwable t) {
// no-op
}
return untranslated(call, translatedExpressions);
}
Aggregations