@@ -0,0 +1,2361 @@
+/*%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage io.prestosql.sql.planner;%0A%0Aimport io.prestosql.metadata.Metadata;%0Aimport io.prestosql.spi.type.Type;%0Aimport io.prestosql.sql.tree.Expression;%0Aimport org.testng.annotations.Test;%0A%0Aimport java.util.Base64;%0A%0Aimport static io.airlift.slice.Slices.utf8Slice;%0Aimport static io.prestosql.metadata.MetadataManager.createTestMetadataManager;%0Aimport static io.prestosql.spi.type.BigintType.BIGINT;%0Aimport static io.prestosql.spi.type.VarbinaryType.VARBINARY;%0Aimport static io.prestosql.spi.type.VarcharType.VARCHAR;%0Aimport static io.prestosql.sql.SqlFormatter.formatSql;%0Aimport static io.prestosql.type.UnknownType.UNKNOWN;%0Aimport static java.nio.charset.StandardCharsets.UTF_8;%0Aimport static org.testng.Assert.assertEquals;%0A%0Apublic class TestLiteralEncoder%0A%7B%0A    private final Metadata metadata = createTestMetadataManager();%0A    private final LiteralEncoder encoder = new LiteralEncoder(metadata);%0A%0A    @Test%0A    public void testEncode()%0A    %7B%0A        assertEncode(null, UNKNOWN, %22null%22);%0A        assertEncode(null, BIGINT, %22CAST(null AS bigint)%22);%0A        assertEncode(123L, BIGINT, %22BIGINT '123'%22);%0A        assertEncode(utf8Slice(%22hello%22), VARCHAR, %22CAST('hello' AS varchar)%22);%0A        assertEncode(utf8Slice(%22hello%22), VARBINARY, literalVarbinary(%22hello%22.getBytes(UTF_8)));%0A    %7D%0A%0A    private void assertEncode(Object value, Type type, String expected)%0A    %7B%0A        Expression expression = encoder.toExpression(value, type);%0A        assertEquals(formatSql(expression), expected);%0A    %7D%0A%0A    private static String literalVarbinary(byte%5B%5D value)%0A    %7B%0A        return %22%5C%22@$literal$%7Cvarbinary%7Cvarbinary@$literal$%3Cf,t%3E(f):t%5C%22%22 +%0A                %22(%5C%22@from_base64%7Cvarbinary%7Cvarchar@from_base64(varchar(x)):varbinary%5C%22%22 +%0A                %22('%22 + Base64.getEncoder().encodeToString(value) + %22'))%22;%0A    %7D%0A%7D%0A

Add test for LiteralEncoder