Search in sources :

Example 1 with UDFLanguage

use of io.crate.expression.udf.UDFLanguage 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

Input (io.crate.data.Input)1 UDFLanguage (io.crate.expression.udf.UDFLanguage)1 UserDefinedFunctionMetadata (io.crate.expression.udf.UserDefinedFunctionMetadata)1 UserDefinedFunctionService (io.crate.expression.udf.UserDefinedFunctionService)1 UserDefinedFunctionsMetadata (io.crate.expression.udf.UserDefinedFunctionsMetadata)1 NodeContext (io.crate.metadata.NodeContext)1 Scalar (io.crate.metadata.Scalar)1 SearchPath.pathWithPGCatalogAndDoc (io.crate.metadata.SearchPath.pathWithPGCatalogAndDoc)1 TransactionContext (io.crate.metadata.TransactionContext)1 Signature (io.crate.metadata.functions.Signature)1 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)1 TestingHelpers.createNodeContext (io.crate.testing.TestingHelpers.createNodeContext)1 DataTypes (io.crate.types.DataTypes)1 List (java.util.List)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1 ScriptException (javax.script.ScriptException)1 Metadata (org.elasticsearch.cluster.metadata.Metadata)1 Index (org.elasticsearch.index.Index)1 Matchers (org.hamcrest.Matchers)1