|
| 1 | +/* |
| 2 | + * Copyright (c) "Neo4j" |
| 3 | + * Neo4j Sweden AB [http://neo4j.com] |
| 4 | + * |
| 5 | + * This file is part of Neo4j. |
| 6 | + * |
| 7 | + * Neo4j is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation, either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | +package org.neo4j.gds.compat._54; |
| 21 | + |
| 22 | +import org.neo4j.gds.annotation.SuppressForbidden; |
| 23 | +import org.neo4j.gds.compat.CompatUserAggregationFunction; |
| 24 | +import org.neo4j.gds.compat.CompatUserAggregator; |
| 25 | +import org.neo4j.internal.kernel.api.exceptions.ProcedureException; |
| 26 | +import org.neo4j.internal.kernel.api.procs.UserAggregationReducer; |
| 27 | +import org.neo4j.internal.kernel.api.procs.UserAggregationUpdater; |
| 28 | +import org.neo4j.internal.kernel.api.procs.UserFunctionSignature; |
| 29 | +import org.neo4j.kernel.api.procedure.CallableUserAggregationFunction; |
| 30 | +import org.neo4j.kernel.api.procedure.Context; |
| 31 | +import org.neo4j.values.AnyValue; |
| 32 | + |
| 33 | +@SuppressForbidden(reason = "This is the compat API") |
| 34 | +public final class CallableUserAggregationFunctionImpl implements CallableUserAggregationFunction { |
| 35 | + private final CompatUserAggregationFunction function; |
| 36 | + |
| 37 | + CallableUserAggregationFunctionImpl(CompatUserAggregationFunction function) { |
| 38 | + this.function = function; |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + public UserFunctionSignature signature() { |
| 43 | + return this.function.signature(); |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public UserAggregationReducer createReducer(Context ctx) throws ProcedureException { |
| 48 | + return new UserAggregatorImpl(this.function.create(ctx)); |
| 49 | + } |
| 50 | + |
| 51 | + private static final class UserAggregatorImpl implements UserAggregationReducer, UserAggregationUpdater { |
| 52 | + private final CompatUserAggregator aggregator; |
| 53 | + |
| 54 | + private UserAggregatorImpl(CompatUserAggregator aggregator) { |
| 55 | + this.aggregator = aggregator; |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public UserAggregationUpdater newUpdater() { |
| 60 | + return this; |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public void update(AnyValue[] input) throws ProcedureException { |
| 65 | + this.aggregator.update(input); |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public void applyUpdates() { |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + public AnyValue result() throws ProcedureException { |
| 74 | + return this.aggregator.result(); |
| 75 | + } |
| 76 | + } |
| 77 | +} |
0 commit comments