Search in sources :

Example 1 with TranslatedExpression

use of com.facebook.presto.expressions.translator.TranslatedExpression in project presto by prestodb.

the class TestRowExpressionTranslator method testMissingFunctionTranslator.

@Test
public void testMissingFunctionTranslator() {
    String untranslated = "ABS(col1)";
    TypeProvider typeProvider = TypeProvider.copyOf(ImmutableMap.of("col1", DOUBLE));
    RowExpression specialForm = sqlToRowExpressionTranslator.translate(expression(untranslated), typeProvider);
    TranslatedExpression translatedExpression = translateWith(specialForm, new TestFunctionTranslator(functionAndTypeManager, buildFunctionTranslator(ImmutableSet.of(TestFunctions.class))), emptyMap());
    assertFalse(translatedExpression.getTranslated().isPresent());
}
Also used : TypeProvider(com.facebook.presto.sql.planner.TypeProvider) RowExpression(com.facebook.presto.spi.relation.RowExpression) TranslatedExpression(com.facebook.presto.expressions.translator.TranslatedExpression) Test(org.testng.annotations.Test)

Example 2 with TranslatedExpression

use of com.facebook.presto.expressions.translator.TranslatedExpression in project presto by prestodb.

the class TestRowExpressionTranslator method testLessThanOperator.

@Test
public void testLessThanOperator() {
    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 LT col2");
}
Also used : TypeProvider(com.facebook.presto.sql.planner.TypeProvider) RowExpression(com.facebook.presto.spi.relation.RowExpression) TranslatedExpression(com.facebook.presto.expressions.translator.TranslatedExpression) Test(org.testng.annotations.Test)

Example 3 with TranslatedExpression

use of com.facebook.presto.expressions.translator.TranslatedExpression in project presto by prestodb.

the class TestRowExpressionTranslator method testEndToEndFunctionTranslation.

@Test
public void testEndToEndFunctionTranslation() {
    String untranslated = "LN(bitwise_and(1, col1))";
    TypeProvider typeProvider = TypeProvider.copyOf(ImmutableMap.of("col1", BIGINT));
    CallExpression callExpression = (CallExpression) sqlToRowExpressionTranslator.translate(expression(untranslated), typeProvider);
    TranslatedExpression translatedExpression = translateWith(callExpression, new TestFunctionTranslator(functionAndTypeManager, buildFunctionTranslator(ImmutableSet.of(TestFunctions.class))), emptyMap());
    assertTrue(translatedExpression.getTranslated().isPresent());
    assertEquals(translatedExpression.getTranslated().get(), "LNof(1 BITWISE_AND col1)");
}
Also used : TypeProvider(com.facebook.presto.sql.planner.TypeProvider) TranslatedExpression(com.facebook.presto.expressions.translator.TranslatedExpression) CallExpression(com.facebook.presto.spi.relation.CallExpression) Test(org.testng.annotations.Test)

Example 4 with TranslatedExpression

use of com.facebook.presto.expressions.translator.TranslatedExpression in project presto by prestodb.

the class TestRowExpressionTranslator method testHiddenFunctionNot.

@Test
public void testHiddenFunctionNot() {
    String untranslated = "NOT true";
    RowExpression specialForm = sqlToRowExpressionTranslator.translate(expression(untranslated), TypeProvider.empty());
    TranslatedExpression translatedExpression = translateWith(specialForm, new TestFunctionTranslator(functionAndTypeManager, buildFunctionTranslator(ImmutableSet.of(TestFunctions.class))), emptyMap());
    assertTrue(translatedExpression.getTranslated().isPresent());
    assertEquals(translatedExpression.getTranslated().get(), "NOT_2 true");
}
Also used : RowExpression(com.facebook.presto.spi.relation.RowExpression) TranslatedExpression(com.facebook.presto.expressions.translator.TranslatedExpression) Test(org.testng.annotations.Test)

Example 5 with TranslatedExpression

use of com.facebook.presto.expressions.translator.TranslatedExpression in project presto by prestodb.

the class TestRowExpressionTranslator method testIncorrectFunctionSignatureInDefinition.

@Test
public void testIncorrectFunctionSignatureInDefinition() {
    String untranslated = "CEIL(col1)";
    TypeProvider typeProvider = TypeProvider.copyOf(ImmutableMap.of("col1", DOUBLE));
    RowExpression specialForm = sqlToRowExpressionTranslator.translate(expression(untranslated), typeProvider);
    TranslatedExpression translatedExpression = translateWith(specialForm, new TestFunctionTranslator(functionAndTypeManager, buildFunctionTranslator(ImmutableSet.of(TestFunctions.class))), emptyMap());
    assertFalse(translatedExpression.getTranslated().isPresent());
}
Also used : TypeProvider(com.facebook.presto.sql.planner.TypeProvider) RowExpression(com.facebook.presto.spi.relation.RowExpression) TranslatedExpression(com.facebook.presto.expressions.translator.TranslatedExpression) Test(org.testng.annotations.Test)

Aggregations

TranslatedExpression (com.facebook.presto.expressions.translator.TranslatedExpression)10 Test (org.testng.annotations.Test)8 RowExpression (com.facebook.presto.spi.relation.RowExpression)7 TypeProvider (com.facebook.presto.sql.planner.TypeProvider)7 JdbcColumnHandle (com.facebook.presto.plugin.jdbc.JdbcColumnHandle)2 CallExpression (com.facebook.presto.spi.relation.CallExpression)2 BigintType (com.facebook.presto.common.type.BigintType)1 BooleanType (com.facebook.presto.common.type.BooleanType)1 CharType (com.facebook.presto.common.type.CharType)1 DateType (com.facebook.presto.common.type.DateType)1 DoubleType (com.facebook.presto.common.type.DoubleType)1 IntegerType (com.facebook.presto.common.type.IntegerType)1 RealType (com.facebook.presto.common.type.RealType)1 SmallintType (com.facebook.presto.common.type.SmallintType)1 TimeType (com.facebook.presto.common.type.TimeType)1 TimeWithTimeZoneType (com.facebook.presto.common.type.TimeWithTimeZoneType)1 TimestampType (com.facebook.presto.common.type.TimestampType)1 TimestampWithTimeZoneType (com.facebook.presto.common.type.TimestampWithTimeZoneType)1 TinyintType (com.facebook.presto.common.type.TinyintType)1 Type (com.facebook.presto.common.type.Type)1