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

UDF Parse Define #1

Open
arcosx opened this issue Dec 16, 2021 · 4 comments
Open

UDF Parse Define #1

arcosx opened this issue Dec 16, 2021 · 4 comments

Comments

@arcosx
Copy link
Contributor

arcosx commented Dec 16, 2021

created by base64

CREATE FUNCTION [FUNCTION NAME](x [TYPE], y [TYPE]) RETURNS  [TYPE] FROM WASM://[base64];
Example:
Wasm Raw Wat
(module
  (func $gcd (param i32 i32) (result i32)
    (local i32)
    block  ;; label = @1
      block  ;; label = @2
        local.get 0
        br_if 0 (;@2;)
        local.get 1
        local.set 2
        br 1 (;@1;)
      end
      loop  ;; label = @2
        local.get 1
        local.get 0
        local.tee 2
        i32.rem_u
        local.set 0
        local.get 2
        local.set 1
        local.get 0
        br_if 0 (;@2;)
      end
    end
    local.get 2
  )
  (export "gcd" (func $gcd))
)

CREATE FUNCTION  gcd (x INT, y INT) RETURNS INT FROM WASM://KG1vZHVsZQogIChmdW5jICRnY2QgKHBhcmFtIGkzMiBpMzIpIChyZXN1bHQgaTMyKQogICAgKGxvY2FsIGkzMikKICAgIGJsb2NrICA7OyBsYWJlbCA9IEAxCiAgICAgIGJsb2NrICA7OyBsYWJlbCA9IEAyCiAgICAgICAgbG9jYWwuZ2V0IDAKICAgICAgICBicl9pZiAwICg7QDI7KQogICAgICAgIGxvY2FsLmdldCAxCiAgICAgICAgbG9jYWwuc2V0IDIKICAgICAgICBiciAxICg7QDE7KQogICAgICBlbmQKICAgICAgbG9vcCAgOzsgbGFiZWwgPSBAMgogICAgICAgIGxvY2FsLmdldCAxCiAgICAgICAgbG9jYWwuZ2V0IDAKICAgICAgICBsb2NhbC50ZWUgMgogICAgICAgIGkzMi5yZW1fdQogICAgICAgIGxvY2FsLnNldCAwCiAgICAgICAgbG9jYWwuZ2V0IDIKICAgICAgICBsb2NhbC5zZXQgMQogICAgICAgIGxvY2FsLmdldCAwCiAgICAgICAgYnJfaWYgMCAoO0AyOykKICAgICAgZW5kCiAgICBlbmQKICAgIGxvY2FsLmdldCAyCiAgKQogIChleHBvcnQgImdjZCIgKGZ1bmMgJGdjZCkpCikKCg== ;

# run
YIELD gcd(5,6);
@Triple-Z
Copy link
Member

Triple-Z commented Dec 17, 2021

CREATE FUNCTION function_name ([params]) RETURN type_spec FROM create_function_from_vendor;
function_param
    : name_label type_spec {
        $$ = new FunctionParam($1, $2->type);
    }
    ;

function_param_list
    : function_param {
        $$ = new FunctionParamList();
        $$->addParam($1);
    }
    | function_param_list COMMA function_param {
        $$ = $1;
        $$->addParam($3);
    }
    ;

create_function_from_vendor
    : HTTP_URL {
        $$ = new FunctionSource(std::string("HTTP"), *$1);
    }
    | WASM_BASE64 {
        $$ = new FunctionSource(std::string("WASM"), *$1);
    }
    ;

create_function_sentence
    : KW_CREATE KW_FUNCTION opt_if_not_exists name_label L_PAREN R_PAREN KW_RETURN type_spec KW_FROM create_function_from_vendor {
        $$ = new CreateFunctionSentence($4, new FunctionParamList(), $8->type, $10, $3);
    }
    | KW_CREATE KW_FUNCTION opt_if_not_exists name_label L_PAREN function_param_list R_PAREN KW_RETURN type_spec KW_FROM create_function_from_vendor {
        $$ = new CreateFunctionSentence($4, $6, $9->type, $11, $3);
    }
    ;

@arcosx
Copy link
Contributor Author

arcosx commented Dec 19, 2021

Can we make this?

CREATE FUNCTION [FUNCTION NAME](x [TYPE], y [TYPE]) RETURNS  [TYPE] FROM WASM://[base64];
CREATE FUNCTION [FUNCTION NAME](x [TYPE], y [TYPE]) RETURNS  [TYPE] FROM WAT://[base64];
CREATE FUNCTION [FUNCTION NAME](x [TYPE], y [TYPE]) RETURNS  [TYPE] FROM PATH://[HTTP Path Or File Path];

@Triple-Z
Copy link
Member

Triple-Z commented Dec 22, 2021

A greatest common divider example:

CREATE FUNCTION gcd_main(x INT32, y INT32) RETURN INT32 FROM WAT://KG1vZHVsZQogIChmdW5jICRnY2QgKHBhcmFtIGkzMiBpMzIpIChyZXN1bHQgaTMyKQogICAgKGxvY2FsIGkzMikKICAgIGJsb2NrICA7OyBsYWJlbCA9IEAxCiAgICAgIGJsb2NrICA7OyBsYWJlbCA9IEAyCiAgICAgICAgbG9jYWwuZ2V0IDAKICAgICAgICBicl9pZiAwICg7QDI7KQogICAgICAgIGxvY2FsLmdldCAxCiAgICAgICAgbG9jYWwuc2V0IDIKICAgICAgICBiciAxICg7QDE7KQogICAgICBlbmQKICAgICAgbG9vcCAgOzsgbGFiZWwgPSBAMgogICAgICAgIGxvY2FsLmdldCAxCiAgICAgICAgbG9jYWwuZ2V0IDAKICAgICAgICBsb2NhbC50ZWUgMgogICAgICAgIGkzMi5yZW1fdQogICAgICAgIGxvY2FsLnNldCAwCiAgICAgICAgbG9jYWwuZ2V0IDIKICAgICAgICBsb2NhbC5zZXQgMQogICAgICAgIGxvY2FsLmdldCAwCiAgICAgICAgYnJfaWYgMCAoO0AyOykKICAgICAgZW5kCiAgICBlbmQKICAgIGxvY2FsLmdldCAyCiAgKQogIChleHBvcnQgIm1haW4iIChmdW5jICRnY2QpKSA7OyBleHBvcnQgd2l0aCBtYWluCik=;

RETURN UDF("gcd", [12, 27]);

DROP FUNCTION gcd;

@arcosx
Copy link
Contributor Author

arcosx commented Dec 23, 2021

A greatest common divider example:

CREATE FUNCTION gcd_main(x INT32, y INT32) RETURN INT32 FROM WASM://KG1vZHVsZQogIChmdW5jICRnY2QgKHBhcmFtIGkzMiBpMzIpIChyZXN1bHQgaTMyKQogICAgKGxvY2FsIGkzMikKICAgIGJsb2NrICA7OyBsYWJlbCA9IEAxCiAgICAgIGJsb2NrICA7OyBsYWJlbCA9IEAyCiAgICAgICAgbG9jYWwuZ2V0IDAKICAgICAgICBicl9pZiAwICg7QDI7KQogICAgICAgIGxvY2FsLmdldCAxCiAgICAgICAgbG9jYWwuc2V0IDIKICAgICAgICBiciAxICg7QDE7KQogICAgICBlbmQKICAgICAgbG9vcCAgOzsgbGFiZWwgPSBAMgogICAgICAgIGxvY2FsLmdldCAxCiAgICAgICAgbG9jYWwuZ2V0IDAKICAgICAgICBsb2NhbC50ZWUgMgogICAgICAgIGkzMi5yZW1fdQogICAgICAgIGxvY2FsLnNldCAwCiAgICAgICAgbG9jYWwuZ2V0IDIKICAgICAgICBsb2NhbC5zZXQgMQogICAgICAgIGxvY2FsLmdldCAwCiAgICAgICAgYnJfaWYgMCAoO0AyOykKICAgICAgZW5kCiAgICBlbmQKICAgIGxvY2FsLmdldCAyCiAgKQogIChleHBvcnQgIm1haW4iIChmdW5jICRnY2QpKSA7OyBleHBvcnQgd2l0aCBtYWluCik=;

RETURN UDF("gcd", [12, 27]);

DROP FUNCTION gcd;

great work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants