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

HHH-18496 Add support for JSON functions #8793

Closed
wants to merge 8 commits into from

Conversation

beikov
Copy link
Contributor

@beikov beikov commented Aug 17, 2024


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


https://hibernate.atlassian.net/browse/HHH-18496

ReturnableType<?> returnType,
SqlAstTranslator<?> walker) {
if ( arguments.errorBehavior() != null ) {
throw new QueryException( "Can't emulate on error clause on H2" );

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
QueryException.QueryException
should be avoided because it has been deprecated.
jsonPath = walker.getLiteralValue( (Expression) arguments.jsonPath() );
}
catch (Exception ex) {
throw new QueryException( "H2 json_value only support literal json paths, but got " + arguments.jsonPath() );

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
QueryException.QueryException
should be avoided because it has been deprecated.
throw new QueryException( "Can't emulate on error clause on H2" );
}
if ( arguments.emptyBehavior() == JsonValueEmptyBehavior.ERROR ) {
throw new QueryException( "Can't emulate error on empty clause on H2" );

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
QueryException.QueryException
should be avoided because it has been deprecated.
ReturnableType<?> returnType,
SqlAstTranslator<?> walker) {
if ( arguments.errorBehavior() != null && arguments.errorBehavior() != JsonValueErrorBehavior.NULL ) {
throw new QueryException( "Can't emulate on error clause on MariaDB" );

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
QueryException.QueryException
should be avoided because it has been deprecated.
throw new QueryException( "Can't emulate on error clause on MariaDB" );
}
if ( arguments.emptyBehavior() != null && arguments.emptyBehavior() != JsonValueEmptyBehavior.NULL ) {
throw new QueryException( "Can't emulate on empty clause on MariaDB" );

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
QueryException.QueryException
should be avoided because it has been deprecated.
scope.inSession( em -> {
try {
//tag::hql-json-value-on-error-example[]
em.createQuery( "select json_value('invalidJson', '$.theInt' error on error) from EntityWithJson e")

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
QueryProducerImplementor.createQuery
should be avoided because it has been deprecated.
scope.inSession( em -> {
try {
//tag::hql-json-value-on-empty-example[]
em.createQuery("select json_value(e.json, '$.nonExisting' error on empty error on error) from EntityWithJson e" )

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
QueryProducerImplementor.createQuery
should be avoided because it has been deprecated.
SqlAstTranslator<?> walker) {
// jsonb_path_query_first errors by default
if ( arguments.errorBehavior() != null && arguments.errorBehavior() != JsonValueErrorBehavior.ERROR ) {
throw new QueryException( "Can't emulate on error clause on CockroachDB" );

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
QueryException.QueryException
should be avoided because it has been deprecated.
throw new QueryException( "Can't emulate on error clause on CockroachDB" );
}
if ( arguments.emptyBehavior() != null && arguments.emptyBehavior() != JsonValueEmptyBehavior.NULL ) {
throw new QueryException( "Can't emulate on empty clause on CockroachDB" );

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
QueryException.QueryException
should be avoided because it has been deprecated.
jsonPath = walker.getLiteralValue( arguments.jsonPath() );
}
catch (Exception ex) {
throw new QueryException( "CockroachDB json_value only support literal json paths, but got " + arguments.jsonPath() );

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
QueryException.QueryException
should be avoided because it has been deprecated.
@beikov beikov changed the title HHH-18496 Add json_value function HHH-18496 Add support for JSON functions Aug 19, 2024
public void testSimple(SessionFactoryScope scope) {
scope.inSession( em -> {
//tag::hql-json-array-example[]
em.createQuery( "select json_array('val1', 'val2'), json_array(1, false, 'val')" ).getResultList();

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
QueryProducerImplementor.createQuery
should be avoided because it has been deprecated.
public void testNullClause(SessionFactoryScope scope) {
scope.inSession( em -> {
//tag::hql-json-array-on-null-example[]
em.createQuery("select json_array(null, 1 null on null)" ).getResultList();

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
QueryProducerImplementor.createQuery
should be avoided because it has been deprecated.
@Test
public void testAbsentOnNull(SessionFactoryScope scope) {
scope.inSession( em -> {
em.createQuery("select json_array(null, 1 absent on null)" ).getResultList();

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
QueryProducerImplementor.createQuery
should be avoided because it has been deprecated.
public void testSimple(SessionFactoryScope scope) {
scope.inSession( em -> {
//tag::hql-json-object-example[]
em.createQuery( "select json_object('key', 'value'), json_object(KEY 'key1' VALUE 'value1', 'key2' VALUE 'value2', 'key3': 'value3')" ).getResultList();

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
QueryProducerImplementor.createQuery
should be avoided because it has been deprecated.
@Test
public void testNullClause(SessionFactoryScope scope) {
scope.inSession( em -> {
em.createQuery("select json_object('key': null null on null)" ).getResultList();

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
QueryProducerImplementor.createQuery
should be avoided because it has been deprecated.
public void testAbsentOnNull(SessionFactoryScope scope) {
scope.inSession( em -> {
//tag::hql-json-object-on-null-example[]
em.createQuery("select json_object('key': null absent on null)" ).getResultList();

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
QueryProducerImplementor.createQuery
should be avoided because it has been deprecated.
@beikov beikov force-pushed the HHH-18496 branch 2 times, most recently from e0417d5 to 4654f88 Compare August 22, 2024 13:24
final String parameterName = ( (JsonPathHelper.JsonParameterIndexAccess) jsonPathElement ).parameterName();
final Expression expression = jsonPathPassingClause.getPassingExpressions().get( parameterName );
if ( expression == null ) {
throw new QueryException( "JSON path [" + jsonPath + "] uses parameter [" + parameterName + "] that is not passed" );

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
QueryException.QueryException
should be avoided because it has been deprecated.
SqlAstTranslator<?> walker) {
// Json dereference errors by default if the JSON is invalid
if ( arguments.errorBehavior() != null && arguments.errorBehavior() != JsonExistsErrorBehavior.ERROR ) {
throw new QueryException( "Can't emulate on error clause on H2" );

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
QueryException.QueryException
should be avoided because it has been deprecated.
jsonPath = walker.getLiteralValue( arguments.jsonPath() );
}
catch (Exception ex) {
throw new QueryException( "H2 json_value only support literal json paths, but got " + arguments.jsonPath() );

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
QueryException.QueryException
should be avoided because it has been deprecated.
final String parameterName = ( (JsonPathHelper.JsonParameterIndexAccess) jsonPathElement ).parameterName();
final Expression expression = passingClause.getPassingExpressions().get( parameterName );
if ( expression == null ) {
throw new QueryException( "JSON path [" + jsonPath + "] uses parameter [" + parameterName + "] that is not passed" );

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
QueryException.QueryException
should be avoided because it has been deprecated.
assert jsonPath.charAt( bracketStartIndex ) == '[';
final int bracketEndIndex = jsonPath.lastIndexOf( ']', endIndex );
if ( bracketEndIndex < bracketStartIndex ) {
throw new QueryException( "Can't emulate non-simple json path expression: " + jsonPath );

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
QueryException.QueryException
should be avoided because it has been deprecated.
ReturnableType<?> returnType,
SqlAstTranslator<?> walker) {
if ( arguments.errorBehavior() == JsonExistsErrorBehavior.TRUE ) {
throw new QueryException( "Can't emulate json_exists(... true on error) on SQL Server" );

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
QueryException.QueryException
should be avoided because it has been deprecated.
scope.inSession( em -> {
try {
//tag::hql-json-exists-on-error-example[]
em.createQuery( "select json_exists('invalidJson', '$.theInt' error on error) from EntityWithJson e")

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
QueryProducerImplementor.createQuery
should be avoided because it has been deprecated.
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@beikov
Copy link
Contributor Author

beikov commented Sep 18, 2024

Superseded by #8979

@beikov beikov closed this Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant