[
https://issues.apache.org/jira/browse/IGNITE-24358?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Vladimir Steshin updated IGNITE-24358:
--------------------------------------
Description:
We should not allow user to override standard and systems (Inginte's) SQL
fucntions with UDF.
Reproducer:
{code:java}
public static class OverrideSystemFunctionLibrary {
/** Overwrites standard 'UPPER(VARCHAR)'. */
@QuerySqlFunction
public static int upper(String s) {
return F.isEmpty(s) ? 0 : s.length();
}
/** Overwrites standard 'UNIX_SECONDS(Timestamp)'. */
@QuerySqlFunction
public static int unix_seconds(Timestamp ts) {
return 1;
}
/** Overwrites Ignite's 'TYPEOF(Object)'. */
@QuerySqlFunction
public static int typeof(Object o) {
return 1;
}
}
/** */
@Test
public void testOverrideSystemFunction() {
assertQuery("SELECT UPPER(?)").withParams("abc").returns("ABC").check();
assertQuery("select UNIX_SECONDS(TIMESTAMP '2021-01-01
00:00:00')").returns(1609459200L).check();
assertQuery("select
TYPEOF(?)").withParams(1L).returns("BIGINT").check();
client.getOrCreateCache(new CacheConfiguration<Integer,
Employer>("testCache")
.setSqlFunctionClasses(OverrideSystemFunctionLibrary.class)
.setSqlSchema("PUBLIC")
.setQueryEntities(F.asList(new QueryEntity(Integer.class,
Employer.class).setTableName("emp")))
);
// Fails with 'Expected: [[ABC]], Actual: [[3]]'
assertQuery("SELECT UPPER(?)").withParams("abc").returns("ABC").check();
// Fails with 'Expected: [[1609459200]], Actual: [[1]]'
assertQuery("select UNIX_SECONDS(TIMESTAMP '2021-01-01
00:00:00')").returns(1609459200L).check();
// Fails with 'Expected: [[BIGINT]], Actual: [[1]]' or even with
other assertion with '-ea'.
assertQuery("select
TYPEOF(?)").withParams(1L).returns("BIGINT").check();
}
{code}
was:
We should not allow user to override standard and systems (Inginte's) SQL
fucntions with UDF.
Reproducer:
{code:java}
public static class OverrideSystemFunctionLibrary {
/** Overwrites standard 'UPPER(VARCHAR)'. */
@QuerySqlFunction
public static int upper(String s) {
return F.isEmpty(s) ? 0 : s.length();
}
/** Overwrites standard 'UNIX_SECONDS(Timestamp)'. */
@QuerySqlFunction
public static int unix_seconds(Timestamp ts) {
return 1;
}
/** Overwrites Ignite's 'TYPEOF(Object)'. */
@QuerySqlFunction
public static int typeof(Object o) {
return 1;
}
}
/** */
@Test
public void testOverrideSystemFunction() {
assertQuery("SELECT UPPER(?)").withParams("abc").returns("ABC").check();
assertQuery("select UNIX_SECONDS(TIMESTAMP '2021-01-01
00:00:00')").returns(1609459200L).check();
assertQuery("select
TYPEOF(?)").withParams(1L).returns("BIGINT").check();
client.getOrCreateCache(new CacheConfiguration<Integer,
Employer>("testCache")
.setSqlFunctionClasses(OverrideSystemFunctionLibrary.class)
.setSqlSchema("PUBLIC")
.setQueryEntities(F.asList(new QueryEntity(Integer.class,
Employer.class).setTableName("emp")))
);
// Fails with 'Expected: [[ABC]], Actual: [[3]]'
//assertQuery("SELECT
UPPER(?)").withParams("abc").returns("ABC").check();
// Fails with 'Expected: [[1609459200]], Actual: [[1]]'
assertQuery("select UNIX_SECONDS(TIMESTAMP '2021-01-01
00:00:00')").returns(1609459200L).check();
// Fails with 'Expected: [[BIGINT]], Actual: [[1]]' or even with
other assertion with '-ea'.
assertQuery("select
TYPEOF(?)").withParams(1L).returns("BIGINT").check();
}
{code}
> Calcite. User is able to override standard or system SQL functions.
> -------------------------------------------------------------------
>
> Key: IGNITE-24358
> URL: https://issues.apache.org/jira/browse/IGNITE-24358
> Project: Ignite
> Issue Type: Bug
> Reporter: Vladimir Steshin
> Priority: Major
> Labels: calcite, ignite-2, ise
>
> We should not allow user to override standard and systems (Inginte's) SQL
> fucntions with UDF.
> Reproducer:
> {code:java}
> public static class OverrideSystemFunctionLibrary {
> /** Overwrites standard 'UPPER(VARCHAR)'. */
> @QuerySqlFunction
> public static int upper(String s) {
> return F.isEmpty(s) ? 0 : s.length();
> }
> /** Overwrites standard 'UNIX_SECONDS(Timestamp)'. */
> @QuerySqlFunction
> public static int unix_seconds(Timestamp ts) {
> return 1;
> }
> /** Overwrites Ignite's 'TYPEOF(Object)'. */
> @QuerySqlFunction
> public static int typeof(Object o) {
> return 1;
> }
> }
> /** */
> @Test
> public void testOverrideSystemFunction() {
> assertQuery("SELECT
> UPPER(?)").withParams("abc").returns("ABC").check();
> assertQuery("select UNIX_SECONDS(TIMESTAMP '2021-01-01
> 00:00:00')").returns(1609459200L).check();
> assertQuery("select
> TYPEOF(?)").withParams(1L).returns("BIGINT").check();
> client.getOrCreateCache(new CacheConfiguration<Integer,
> Employer>("testCache")
> .setSqlFunctionClasses(OverrideSystemFunctionLibrary.class)
> .setSqlSchema("PUBLIC")
> .setQueryEntities(F.asList(new QueryEntity(Integer.class,
> Employer.class).setTableName("emp")))
> );
> // Fails with 'Expected: [[ABC]], Actual: [[3]]'
> assertQuery("SELECT
> UPPER(?)").withParams("abc").returns("ABC").check();
> // Fails with 'Expected: [[1609459200]], Actual: [[1]]'
> assertQuery("select UNIX_SECONDS(TIMESTAMP '2021-01-01
> 00:00:00')").returns(1609459200L).check();
> // Fails with 'Expected: [[BIGINT]], Actual: [[1]]' or even with
> other assertion with '-ea'.
> assertQuery("select
> TYPEOF(?)").withParams(1L).returns("BIGINT").check();
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)