Skip to content

Commit

Permalink
feat(udf doc gen): simplify supported types (#3341)
Browse files Browse the repository at this point in the history
* feat(udf doc gen): simplify supported types

list<...> -> list<any>

* fix: patch_markdown.sh
  • Loading branch information
aceforeverd authored Jul 11, 2023
1 parent c27955f commit fc8f7b7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
27 changes: 20 additions & 7 deletions hybridse/tools/documentation/udf_doxygen/export_udf_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,22 @@ def process_doc(doc):
lines[i] = lines[i][indent:]
return "\n".join(lines)

def surrond_backquote(t):
return f"`{t}`"

def to_list_type(t):
return f"`list<{t}>`"


numeric_types = frozenset(["int16", "int32", "int64", "float", "double"])
all_basic_types = frozenset(["bool", "int16", "int32", "int64", "float", "double", "string", "timestamp", "date"])

numeric_types_code = list(map(surrond_backquote, numeric_types))
list_numeric_types_code = list(map(to_list_type, numeric_types))
all_types_code = list(map(surrond_backquote, all_basic_types))
list_all_types_code = list(map(to_list_type, all_basic_types))

def merge_arith_types(signature_set):
arith_types = frozenset(["`int16`", "`int32`", "`int64`", "`float`", "`double`"])
arith_list_types = frozenset(["`list<int16>`", "`list<int32>`", "`list<int64>`", "`list<float>`", "`list<double>`"])
all_basic_types = frozenset(["`bool`", "`int16`", "`int32`", "`int64`",
"`float`", "`double`", "`string`", "`timestamp`", "`date`"])
found = True

def _find_and_merge(arg_types, idx, list_ty, merge_ty):
Expand Down Expand Up @@ -87,14 +97,17 @@ def _find_and_merge(arg_types, idx, list_ty, merge_ty):
for key in signature_set:
arg_types = [_ for _ in signature_set[key]]
for i in range(len(arg_types)):
if _find_and_merge(arg_types, i, all_basic_types, "`any`"):
if _find_and_merge(arg_types, i, all_types_code, "`any`"):
# NOTE: must merge any before number
found = True
break
elif _find_and_merge(arg_types, i, arith_types, "`number`"):
elif _find_and_merge(arg_types, i, list_all_types_code, "`list<any>`"):
found = True
break
elif _find_and_merge(arg_types, i, numeric_types_code, "`number`"):
found = True
break
elif _find_and_merge(arg_types, i, arith_list_types, "`list<number>`"):
elif _find_and_merge(arg_types, i, list_numeric_types_code, "`list<number>`"):
found = True
break
if found:
Expand Down
7 changes: 4 additions & 3 deletions hybridse/tools/documentation/udf_doxygen/patch_markdown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ Types in documents here may a little different from real types in OpenMLDB SQL,
\n\
| Type literal | Same as any of those types in OpenMLDB SQL |\n\
| --------- | -------------------------------------- |\n\
| number | \`int16, int32, int64, float, double\` |\n\
| any | \`bool, int16, int32, int64, float, double, string, timestamp, date\` |\n\
| list<number> | \`list<int16>, list<int32>, list<int64>, list<float>, list<double>\` |\n\
| \`number\` | \`int16, int32, int64, float, double\` |\n\
| \`any\` | \`bool, int16, int32, int64, float, double, string, timestamp, date\` |\n\
| \`list<number>\` | \`list<int16>, list<int32>, list<int64>, list<float>, list<double>\` |\n\
| \`list<any>\` | \`list<bool>, list<int16>, list<int32>, list<int64>, list<float>, list<double>, list<string>, list<timestamp>, list<date>\` |\n\
\n\
## Functions/g" "$PATCH_FILE"

0 comments on commit fc8f7b7

Please sign in to comment.