Search in sources :

Example 6 with UserDefinedFunctionMetadata

use of io.crate.expression.udf.UserDefinedFunctionMetadata in project crate by crate.

the class DocSchemaInfoTest method setup.

@Before
public void setup() throws Exception {
    nodeCtx = createNodeContext();
    udfService = new UserDefinedFunctionService(clusterService, nodeCtx);
    udfService.registerLanguage(new UDFLanguage() {

        @Override
        public Scalar createFunctionImplementation(UserDefinedFunctionMetadata metadata, Signature signature) throws ScriptException {
            String error = validate(metadata);
            if (error != null) {
                throw new ScriptException("this is not Burlesque");
            }
            return new Scalar<>() {

                @Override
                public Object evaluate(TransactionContext txnCtx, NodeContext nodeCtx, Input[] args) {
                    return null;
                }

                @Override
                public Signature signature() {
                    return signature;
                }

                @Override
                public Signature boundSignature() {
                    return signature;
                }
            };
        }

        @Override
        @Nullable
        public String validate(UserDefinedFunctionMetadata metadata) {
            if (!metadata.definition().equals("\"Hello, World!\"Q")) {
                return "this is not Burlesque";
            }
            return null;
        }

        @Override
        public String name() {
            return "burlesque";
        }
    });
    docSchemaInfo = new DocSchemaInfo("doc", clusterService, nodeCtx, udfService, (ident, state) -> null, new TestingDocTableInfoFactory(Map.of()));
}
Also used : UserDefinedFunctionService(io.crate.expression.udf.UserDefinedFunctionService) Input(io.crate.data.Input) UDFLanguage(io.crate.expression.udf.UDFLanguage) TransactionContext(io.crate.metadata.TransactionContext) NodeContext(io.crate.metadata.NodeContext) UserDefinedFunctionService(io.crate.expression.udf.UserDefinedFunctionService) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) Signature(io.crate.metadata.functions.Signature) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Index(org.elasticsearch.index.Index) UserDefinedFunctionsMetadata(io.crate.expression.udf.UserDefinedFunctionsMetadata) UserDefinedFunctionMetadata(io.crate.expression.udf.UserDefinedFunctionMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) List(java.util.List) DataTypes(io.crate.types.DataTypes) Map(java.util.Map) Scalar(io.crate.metadata.Scalar) TestingHelpers.createNodeContext(io.crate.testing.TestingHelpers.createNodeContext) Nullable(javax.annotation.Nullable) SearchPath.pathWithPGCatalogAndDoc(io.crate.metadata.SearchPath.pathWithPGCatalogAndDoc) Before(org.junit.Before) ScriptException(javax.script.ScriptException) NodeContext(io.crate.metadata.NodeContext) TestingHelpers.createNodeContext(io.crate.testing.TestingHelpers.createNodeContext) UserDefinedFunctionMetadata(io.crate.expression.udf.UserDefinedFunctionMetadata) Scalar(io.crate.metadata.Scalar) ScriptException(javax.script.ScriptException) Input(io.crate.data.Input) TransactionContext(io.crate.metadata.TransactionContext) Signature(io.crate.metadata.functions.Signature) UDFLanguage(io.crate.expression.udf.UDFLanguage) Nullable(javax.annotation.Nullable) Before(org.junit.Before)

Aggregations

UserDefinedFunctionMetadata (io.crate.expression.udf.UserDefinedFunctionMetadata)6 Test (org.junit.Test)4 UserDefinedFunctionsMetadata (io.crate.expression.udf.UserDefinedFunctionsMetadata)3 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)3 ScriptException (javax.script.ScriptException)2 Metadata (org.elasticsearch.cluster.metadata.Metadata)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 AnalyzedCreateFunction (io.crate.analyze.AnalyzedCreateFunction)1 FunctionArgumentDefinition (io.crate.analyze.FunctionArgumentDefinition)1 SymbolEvaluator (io.crate.analyze.SymbolEvaluator)1 Input (io.crate.data.Input)1 Row (io.crate.data.Row)1 Row1 (io.crate.data.Row1)1 RowConsumer (io.crate.data.RowConsumer)1 OneRowActionListener (io.crate.execution.support.OneRowActionListener)1 Symbol (io.crate.expression.symbol.Symbol)1 CreateUserDefinedFunctionRequest (io.crate.expression.udf.CreateUserDefinedFunctionRequest)1 UDFLanguage (io.crate.expression.udf.UDFLanguage)1 UserDefinedFunctionService (io.crate.expression.udf.UserDefinedFunctionService)1 FunctionName (io.crate.metadata.FunctionName)1