Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.calcite.sql.SqlTimeLiteral;
import org.apache.calcite.sql.SqlTimestampLiteral;
import org.apache.calcite.sql.SqlWriter;
import org.apache.calcite.sql.fun.SqlLibraryOperators;
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import org.apache.calcite.sql.parser.SqlParserPos;
import org.apache.calcite.sql.type.SqlTypeName;
Expand Down Expand Up @@ -228,6 +229,20 @@ private static SqlDataTypeSpec createSqlDataTypeSpecByName(String typeAlias,
return;
}

// refer to https://clickhouse.com/docs/sql-reference/functions/url-functions#encodeURLComponent
if (call.getOperator() == SqlLibraryOperators.URL_ENCODE) {
RelToSqlConverterUtil.specialOperatorByName("encodeURLComponent")
.unparse(writer, call, 0, 0);
return;
}

// refer to https://clickhouse.com/docs/sql-reference/functions/url-functions#decodeURLComponent
if (call.getOperator() == SqlLibraryOperators.URL_DECODE) {
RelToSqlConverterUtil.specialOperatorByName("decodeURLComponent")
.unparse(writer, call, 0, 0);
return;
}

switch (call.getKind()) {
case MAP_VALUE_CONSTRUCTOR:
writer.print(call.getOperator().getName().toLowerCase(Locale.ROOT));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3701,6 +3701,19 @@ private SqlDialect nonOrdinalDialect() {
sql(query2).withSpark().ok(expected2);
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-7408">[CALCITE-7408]
* URL_ENCODE/URL_DECODE is unparsed incorrectly for ClickHouseSqlDialect</a>. */
@Test void testUrlencodeAndUrldecode() {
final String query = "SELECT URL_ENCODE(\"product_name\") from \"product\"";
final String expected = "SELECT encodeURLComponent(`product_name`)\nFROM `foodmart`.`product`";
sql(query).withLibrary(SqlLibrary.SPARK).withClickHouse().ok(expected);

final String query1 = "SELECT URL_DECODE(\"product_name\") from \"product\"";
final String expected1 = "SELECT decodeURLComponent(`product_name`)\nFROM `foodmart`.`product`";
sql(query1).withLibrary(SqlLibrary.SPARK).withClickHouse().ok(expected1);
}

@Test void testInstrFunction4Operands() {
final String query = "SELECT INSTR('ABC', 'A', 1, 1) from \"product\"";
final String expectedBQ = "SELECT INSTR('ABC', 'A', 1, 1)\n"
Expand Down
Loading