Skip to content

Commit

Permalink
Merge pull request #9557 from neo-technology/dev-compat-30
Browse files Browse the repository at this point in the history
5.24 compatibility
  • Loading branch information
knutwalker authored Aug 29, 2024
2 parents 0c10772 + 260d013 commit 7c8449e
Show file tree
Hide file tree
Showing 21 changed files with 459 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
*/
package org.neo4j.gds.compat._522;

import org.neo4j.collection.RawIterator;
import org.neo4j.configuration.Config;
import org.neo4j.dbms.api.DatabaseNotFoundException;
import org.neo4j.exceptions.KernelException;
import org.neo4j.gds.annotation.SuppressForbidden;
import org.neo4j.gds.compat.CompatCallableProcedure;
import org.neo4j.gds.compat.Neo4jProxyApi;
import org.neo4j.gds.compat.batchimport.BatchImporter;
import org.neo4j.gds.compat.batchimport.ExecutionMonitor;
Expand All @@ -28,14 +33,25 @@
import org.neo4j.gds.compat.batchimport.input.Collector;
import org.neo4j.gds.compat.batchimport.input.Estimates;
import org.neo4j.gds.compat.batchimport.input.ReadableGroups;
import org.neo4j.internal.kernel.api.exceptions.ProcedureException;
import org.neo4j.internal.kernel.api.procs.ProcedureSignature;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.layout.DatabaseLayout;
import org.neo4j.kernel.api.ResourceMonitor;
import org.neo4j.kernel.api.exceptions.Status;
import org.neo4j.kernel.api.procedure.CallableProcedure;
import org.neo4j.kernel.api.procedure.Context;
import org.neo4j.kernel.impl.query.QueryExecutionKernelException;
import org.neo4j.logging.internal.LogService;
import org.neo4j.scheduler.JobScheduler;
import org.neo4j.values.AnyValue;
import org.neo4j.values.SequenceValue;

import java.io.OutputStream;
import java.util.function.LongConsumer;

import static org.neo4j.internal.helpers.collection.Iterators.asRawIterator;

public final class Neo4jProxyImpl implements Neo4jProxyApi {

@Override
Expand Down Expand Up @@ -141,4 +157,76 @@ public Estimates knownEstimates(
numberOfNodeLabels
);
}

@Override
public void rethrowUnlessDuplicateRegistration(ProcedureException e) throws KernelException {
if (e.status() == Status.Procedure.ProcedureRegistrationFailed && e.getMessage().contains("already in use")) {
return;
}
throw e;
}

@Override
public CallableProcedure callableProcedure(CompatCallableProcedure procedure) {
@SuppressForbidden(reason = "This is the compat API")
final class CallableProcedureImpl implements CallableProcedure {
private final CompatCallableProcedure procedure;

private CallableProcedureImpl(CompatCallableProcedure procedure) {
this.procedure = procedure;
}

@Override
public ProcedureSignature signature() {
return this.procedure.signature();
}

@Override
public RawIterator<AnyValue[], ProcedureException> apply(
Context ctx,
AnyValue[] input,
ResourceMonitor resourceMonitor
) throws ProcedureException {
return asRawIterator(this.procedure.apply(ctx, input));
}
}

return new CallableProcedureImpl(procedure);
}

@Override
public int sequenceSizeAsInt(SequenceValue sequenceValue) {
return sequenceValue.length();
}

@Override
public RuntimeException queryExceptionAsRuntimeException(Throwable throwable) {
if (throwable instanceof RuntimeException) {
return (RuntimeException) throwable;
} else if (throwable instanceof QueryExecutionKernelException) {
return ((QueryExecutionKernelException) throwable).asUserException();
} else {
return new RuntimeException(throwable);
}
}

@Override
public ProcedureException procedureCallFailed(String message, Object... args) {
return new ProcedureException(Status.Procedure.ProcedureCallFailed, message, args);
}

@Override
public ProcedureException procedureCallFailed(Throwable reason, String message, Object... args) {
return new ProcedureException(Status.Procedure.ProcedureCallFailed, reason, message, args);
}

@Override
public String exceptionMessage(Throwable e) {
return e.getMessage();
}

@Override
public DatabaseNotFoundException databaseNotFoundException(String message) {
throw new DatabaseNotFoundException(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
*/
package org.neo4j.gds.compat._523;

import org.neo4j.collection.RawIterator;
import org.neo4j.configuration.Config;
import org.neo4j.dbms.api.DatabaseNotFoundException;
import org.neo4j.exceptions.KernelException;
import org.neo4j.gds.annotation.SuppressForbidden;
import org.neo4j.gds.compat.CompatCallableProcedure;
import org.neo4j.gds.compat.Neo4jProxyApi;
import org.neo4j.gds.compat.batchimport.BatchImporter;
import org.neo4j.gds.compat.batchimport.ExecutionMonitor;
Expand All @@ -28,14 +33,25 @@
import org.neo4j.gds.compat.batchimport.input.Collector;
import org.neo4j.gds.compat.batchimport.input.Estimates;
import org.neo4j.gds.compat.batchimport.input.ReadableGroups;
import org.neo4j.internal.kernel.api.exceptions.ProcedureException;
import org.neo4j.internal.kernel.api.procs.ProcedureSignature;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.layout.DatabaseLayout;
import org.neo4j.kernel.api.ResourceMonitor;
import org.neo4j.kernel.api.exceptions.Status;
import org.neo4j.kernel.api.procedure.CallableProcedure;
import org.neo4j.kernel.api.procedure.Context;
import org.neo4j.kernel.impl.query.QueryExecutionKernelException;
import org.neo4j.logging.internal.LogService;
import org.neo4j.scheduler.JobScheduler;
import org.neo4j.values.AnyValue;
import org.neo4j.values.SequenceValue;

import java.io.OutputStream;
import java.util.function.LongConsumer;

import static org.neo4j.internal.helpers.collection.Iterators.asRawIterator;

public final class Neo4jProxyImpl implements Neo4jProxyApi {

@Override
Expand Down Expand Up @@ -141,4 +157,76 @@ public Estimates knownEstimates(
numberOfNodeLabels
);
}

@Override
public void rethrowUnlessDuplicateRegistration(ProcedureException e) throws KernelException {
if (e.status() == Status.Procedure.ProcedureRegistrationFailed && e.getMessage().contains("already in use")) {
return;
}
throw e;
}

@Override
public CallableProcedure callableProcedure(CompatCallableProcedure procedure) {
@SuppressForbidden(reason = "This is the compat API")
final class CallableProcedureImpl implements CallableProcedure {
private final CompatCallableProcedure procedure;

private CallableProcedureImpl(CompatCallableProcedure procedure) {
this.procedure = procedure;
}

@Override
public ProcedureSignature signature() {
return this.procedure.signature();
}

@Override
public RawIterator<AnyValue[], ProcedureException> apply(
Context ctx,
AnyValue[] input,
ResourceMonitor resourceMonitor
) throws ProcedureException {
return asRawIterator(this.procedure.apply(ctx, input));
}
}

return new CallableProcedureImpl(procedure);
}

@Override
public int sequenceSizeAsInt(SequenceValue sequenceValue) {
return sequenceValue.length();
}

@Override
public RuntimeException queryExceptionAsRuntimeException(Throwable throwable) {
if (throwable instanceof RuntimeException) {
return (RuntimeException) throwable;
} else if (throwable instanceof QueryExecutionKernelException) {
return ((QueryExecutionKernelException) throwable).asUserException();
} else {
return new RuntimeException(throwable);
}
}

@Override
public ProcedureException procedureCallFailed(String message, Object... args) {
return new ProcedureException(Status.Procedure.ProcedureCallFailed, message, args);
}

@Override
public ProcedureException procedureCallFailed(Throwable reason, String message, Object... args) {
return new ProcedureException(Status.Procedure.ProcedureCallFailed, reason, message, args);
}

@Override
public String exceptionMessage(Throwable e) {
return e.getMessage();
}

@Override
public DatabaseNotFoundException databaseNotFoundException(String message) {
throw new DatabaseNotFoundException(message);
}
}
3 changes: 3 additions & 0 deletions compatibility/5.24/neo4j-kernel-adapter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ dependencies {
compileOnly(group: 'org.neo4j', name: 'neo4j-import-api', version: neos.'5.24') {
transitive = false
}
compileOnly(group: 'org.neo4j', name: 'neo4j-gql-status', version: neos.'5.24') {
transitive = false
}

implementation project(':neo4j-kernel-adapter-api')
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
*/
package org.neo4j.gds.compat._524;

import org.neo4j.collection.ResourceRawIterator;
import org.neo4j.configuration.Config;
import org.neo4j.dbms.api.DatabaseNotFoundException;
import org.neo4j.exceptions.KernelException;
import org.neo4j.gds.annotation.SuppressForbidden;
import org.neo4j.gds.compat.CompatCallableProcedure;
import org.neo4j.gds.compat.Neo4jProxyApi;
import org.neo4j.gds.compat.batchimport.BatchImporter;
import org.neo4j.gds.compat.batchimport.ExecutionMonitor;
Expand All @@ -28,14 +33,25 @@
import org.neo4j.gds.compat.batchimport.input.Collector;
import org.neo4j.gds.compat.batchimport.input.Estimates;
import org.neo4j.gds.compat.batchimport.input.ReadableGroups;
import org.neo4j.internal.kernel.api.exceptions.ProcedureException;
import org.neo4j.internal.kernel.api.procs.ProcedureSignature;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.layout.DatabaseLayout;
import org.neo4j.kernel.api.ResourceMonitor;
import org.neo4j.kernel.api.exceptions.Status;
import org.neo4j.kernel.api.procedure.CallableProcedure;
import org.neo4j.kernel.api.procedure.Context;
import org.neo4j.kernel.impl.query.QueryExecutionKernelException;
import org.neo4j.logging.internal.LogService;
import org.neo4j.scheduler.JobScheduler;
import org.neo4j.values.AnyValue;
import org.neo4j.values.SequenceValue;

import java.io.OutputStream;
import java.util.function.LongConsumer;

import static org.neo4j.internal.helpers.collection.Iterators.asRawIterator;

public final class Neo4jProxyImpl implements Neo4jProxyApi {

@Override
Expand Down Expand Up @@ -141,4 +157,76 @@ public Estimates knownEstimates(
numberOfNodeLabels
);
}

@Override
public void rethrowUnlessDuplicateRegistration(ProcedureException e) throws KernelException {
if (e.status() == Status.Procedure.ProcedureRegistrationFailed && e.getMessage().contains("already in use")) {
return;
}
throw e;
}

@Override
public CallableProcedure callableProcedure(CompatCallableProcedure procedure) {
@SuppressForbidden(reason = "This is the compat API")
final class CallableProcedureImpl implements CallableProcedure {
private final CompatCallableProcedure procedure;

private CallableProcedureImpl(CompatCallableProcedure procedure) {
this.procedure = procedure;
}

@Override
public ProcedureSignature signature() {
return this.procedure.signature();
}

@Override
public ResourceRawIterator<AnyValue[], ProcedureException> apply(
Context context,
AnyValue[] anyValues,
ResourceMonitor resourceMonitor
) throws ProcedureException {
return asRawIterator(this.procedure.apply(context, anyValues));
}
}

return new CallableProcedureImpl(procedure);
}

@Override
public int sequenceSizeAsInt(SequenceValue sequenceValue) {
return sequenceValue.intSize();
}

@Override
public RuntimeException queryExceptionAsRuntimeException(Throwable throwable) {
if (throwable instanceof RuntimeException) {
return (RuntimeException) throwable;
} else if (throwable instanceof QueryExecutionKernelException) {
return ((QueryExecutionKernelException) throwable).asUserException();
} else {
return new RuntimeException(throwable);
}
}

@Override
public ProcedureException procedureCallFailed(String message, Object... args) {
return new ProcedureException(Status.Procedure.ProcedureCallFailed, message, args);
}

@Override
public ProcedureException procedureCallFailed(Throwable reason, String message, Object... args) {
return new ProcedureException(Status.Procedure.ProcedureCallFailed, reason, message, args);
}

@Override
public String exceptionMessage(Throwable e) {
return e.getMessage();
}

@Override
public DatabaseNotFoundException databaseNotFoundException(String message) {
throw new DatabaseNotFoundException(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
*/
package org.neo4j.gds.compat;

import org.neo4j.collection.RawIterator;
import org.neo4j.internal.kernel.api.exceptions.ProcedureException;
import org.neo4j.internal.kernel.api.procs.ProcedureSignature;
import org.neo4j.kernel.api.procedure.Context;
import org.neo4j.values.AnyValue;

import java.util.stream.Stream;

public interface CompatCallableProcedure {
ProcedureSignature signature();

RawIterator<AnyValue[], ProcedureException> apply(Context ctx, AnyValue[] input) throws ProcedureException;
Stream<AnyValue[]> apply(Context ctx, AnyValue[] input) throws ProcedureException;
}
Loading

0 comments on commit 7c8449e

Please sign in to comment.