Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResourceKeyspacePopulate fails on CQL scripts with $$ delimited string constants containing semicolons #1517

Closed
tmoschou opened this issue Aug 19, 2024 · 1 comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@tmoschou
Copy link

ResourceKeyspacePopulate and ScriptUtils fails to apply CQL scripts with $$ delimited string constants containing semicolons. In particular for UDFs which should always contain a semicolon in the code block.

CREATE FUNCTION IF NOT EXISTS fromBase64Url(base64 text)
    RETURNS NULL ON NULL INPUT
    RETURNS blob
    LANGUAGE java
    AS $$
        return java.nio.ByteBuffer.wrap(
            java.util.Base64.getUrlDecoder().decode(base64)
        );
    $$;

CREATE FUNCTION IF NOT EXISTS toBase64Url(binary blob)
    RETURNS NULL ON NULL INPUT
    RETURNS text
    LANGUAGE java
    AS $$
        final byte[] array = new byte[binary.remaining()];
        binary.get(array);
        return java.util.Base64.getUrlEncoder().withoutPadding().encodeToString(array);
    $$;

See https://cassandra.apache.org/doc/stable/cassandra/cql/definitions.html#constants

ScriptUtils is attempting to manually parse the script to split on semicolons.

Caused by: org.springframework.data.cassandra.core.cql.session.init.ScriptStatementFailedException: Failed to execute CQL script statement #5 of class path resource [cql/01-init-tables.cql]: CREATE FUNCTION IF NOT EXISTS fromBase64Url(base64 text) RETURNS NULL ON NULL INPUT RETURNS blob LANGUAGE java AS $$ return java.nio.ByteBuffer.wrap( java.util.Base64.getUrlDecoder().decode(base64) )
	at org.springframework.data.cassandra.core.cql.session.init.ScriptUtils.executeCqlScript(ScriptUtils.java:554)
	at org.springframework.data.cassandra.core.cql.session.init.ResourceKeyspacePopulator.populate(ResourceKeyspacePopulator.java:251)
	at org.springframework.data.cassandra.core.cql.session.init.SessionFactoryInitializer.execute(SessionFactoryInitializer.java:107)
	at org.springframework.data.cassandra.core.cql.session.init.SessionFactoryInitializer.afterPropertiesSet(SessionFactoryInitializer.java:91)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1802)
	... 19 common frames omitted
Caused by: com.datastax.oss.driver.api.core.servererrors.SyntaxError: line 1:198 mismatched character ')' expecting '$'
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 19, 2024
@mp911de
Copy link
Member

mp911de commented Aug 19, 2024

This is expected as the default statement separator is ;. Script utils do not parse the statements in terms of an AST, instead, it uses it in the sense of String.split.

Instead, please use a different character for your scripts and in the config if you want to import functions.

@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Aug 19, 2024
@mp911de mp911de added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

3 participants