diff --git a/ibis-server/resources/function_list/mysql.csv b/ibis-server/resources/function_list/mysql.csv index f24cf1241..584bbcd89 100644 --- a/ibis-server/resources/function_list/mysql.csv +++ b/ibis-server/resources/function_list/mysql.csv @@ -1,85 +1,59 @@ -function_type,name,return_type,description -scalar,abs,int,"Returns the absolute value of a number" -scalar,concat,varchar,"Concatenates two or more strings together" -scalar,substr,varchar,"Returns a substring from a string starting at a specified position" -scalar,upper,varchar,"Converts a string to uppercase" -scalar,lower,varchar,"Converts a string to lowercase" -scalar,trim,varchar,"Removes leading and trailing spaces from a string" -scalar,date_format,varchar,"Formats a date according to the specified format" -scalar,coalesce,any,"Returns the first non-null value in a list" -scalar,ifnull,any,"Returns the first argument if it is not NULL, otherwise returns the second argument" -scalar,if,any,"Returns one value if a condition is TRUE, or another value if a condition is FALSE" -scalar,case,any,"Makes conditional statements like if-then-else" -scalar,cast,any,"Converts a value from one data type to another" -scalar,round,decimal,"Rounds a number to a specified number of decimal places" -scalar,floor,int,"Returns the largest integer value less than or equal to a number" -scalar,ceiling,int,"Returns the smallest integer value greater than or equal to a number" -scalar,length,int,"Returns the length of a string in bytes" -scalar,char_length,int,"Returns the length of a string in characters" -scalar,datediff,int,"Returns the number of days between two dates" -scalar,timestampdiff,int,"Returns the difference between two datetime expressions" -scalar,uuid,varchar,"Returns a Universal Unique Identifier" -scalar,md5,varchar,"Calculates an MD5 hash value" -scalar,replace,varchar,"Replaces all occurrences of a substring within a string" -scalar,inet_aton,int,"Converts an IPv4 address to numeric value" -scalar,inet_ntoa,varchar,"Converts numeric value to IPv4 address" -scalar,find_in_set,int,"Returns position of string within a comma-separated list" -scalar,format,varchar,"Formats number to specified decimal places and adds thousand separators" -scalar,from_unixtime,datetime,"Converts Unix timestamp to datetime" -scalar,hex,varchar,"Returns hexadecimal representation of a decimal or string value" -scalar,unhex,varchar,"Converts hexadecimal value to string" -scalar,instr,int,"Returns position of first occurrence of substring in string" -scalar,lcase,varchar,"Synonym for LOWER()" -scalar,left,varchar,"Returns the leftmost number of characters from string" -scalar,right,varchar,"Returns the rightmost number of characters from string" -scalar,lpad,varchar,"Left-pads string with specified characters to certain length" -scalar,rpad,varchar,"Right-pads string with specified characters to certain length" -scalar,ltrim,varchar,"Removes leading spaces from string" -scalar,rtrim,varchar,"Removes trailing spaces from string" -scalar,make_set,varchar,"Returns set of comma-separated strings that have corresponding bit set" -scalar,power,decimal,"Returns the value of number raised to specified power" -scalar,quote,varchar,"Escapes string and adds single quotes" -scalar,repeat,varchar,"Repeats a string specified number of times" -scalar,reverse,varchar,"Reverses the characters in a string" -scalar,soundex,varchar,"Returns soundex string of given string" -scalar,space,varchar,"Returns string of specified number of spaces" -scalar,substring_index,varchar,"Returns substring from string before specified number of delimiter occurs" -scalar,time_format,varchar,"Formats time according to format specification" -scalar,time_to_sec,int,"Converts time value to seconds" -scalar,sec_to_time,time,"Converts seconds to time value" -scalar,truncate,decimal,"Truncates number to specified number of decimal places" -scalar,unix_timestamp,int,"Returns Unix timestamp" -scalar,weekday,int,"Returns weekday index (0=Monday, 6=Sunday)" -scalar,yearweek,int,"Returns year and week number" -scalar,date_add,datetime,"Adds time/date interval to date" -scalar,date_sub,datetime,"Subtracts time/date interval from date" -scalar,now,datetime,"Synonym for CURRENT_TIMESTAMP()" -scalar,dayname,varchar,"Returns name of weekday" -scalar,monthname,varchar,"Returns name of month" -scalar,quarter,int,"Returns quarter from date (1 to 4)" -scalar,week,int,"Returns week number" -aggregate,count,int,"Returns the number of rows in a group" -aggregate,sum,decimal/int,"Returns the sum of values in a group" -aggregate,avg,decimal,"Returns the average of values in a group" -aggregate,min,any,"Returns the minimum value in a group" -aggregate,max,any,"Returns the maximum value in a group" -aggregate,group_concat,varchar,"Returns a concatenated string from a group" -aggregate,std,decimal,"Returns the population standard deviation" -aggregate,variance,decimal,"Returns the population variance" -aggregate,bit_and,int,"Returns the bitwise AND of all bits in a group" -aggregate,bit_or,int,"Returns the bitwise OR of all bits in a group" -aggregate,bit_xor,int,"Returns the bitwise XOR of all bits in a group" -aggregate,json_arrayagg,json,"Aggregates result set as JSON array" -aggregate,json_objectagg,json,"Aggregates result set as JSON object" -aggregate,count_distinct,int,"Returns count of distinct values in group" -window,row_number,int,"Returns the sequential number of a row within a partition" -window,rank,int,"Returns the rank of current row within a partition, with gaps" -window,dense_rank,int,"Returns the rank of current row within a partition, without gaps" -window,lag,any,"Returns the value from a previous row in the partition" -window,lead,any,"Returns the value from a following row in the partition" -window,first_value,any,"Returns the first value in the window frame" -window,last_value,any,"Returns the last value in the window frame" -window,nth_value,any,"Returns value from the nth row of the window frame" -window,ntile,int,"Divides partition into specified number of groups" -window,percent_rank,decimal,"Returns relative rank of current row (rank-1)/(total rows-1)" -window,cume_dist,decimal,"Returns cumulative distribution of current row" +function_type,name,return_type,param_names,param_types,description +scalar,abs,int,,int,"Returns the absolute value of a number" +scalar,concat,varchar,,"varchar,varchar","Concatenates two or more strings together" +scalar,substr,varchar,,"varchar,int,int","Returns a substring from a string starting at a specified position" +scalar,upper,varchar,,"varchar","Converts a string to uppercase" +scalar,lower,varchar,,"varchar","Converts a string to lowercase" +scalar,date_format,varchar,,"date,varchar","Formats a date according to the specified format" +scalar,coalesce,any,,"any,any","Returns the first non-null value in a list" +scalar,if,any,,"boolean,any,any","Returns one value if a condition is TRUE, or another value if a condition is FALSE" +scalar,round,decimal,,"decimal,int","Rounds a number to a specified number of decimal places" +scalar,floor,int,,"decimal","Returns the largest integer value less than or equal to a number" +scalar,ceiling,int,,"decimal","Returns the smallest integer value greater than or equal to a number" +scalar,length,int,,"varchar","Returns the length of a string in bytes" +scalar,char_length,int,,"varchar","Returns the length of a string in characters" +scalar,datediff,int,,"date,date","Returns the number of days between two dates" +scalar,timestampdiff,int,,"varchar,datetime,datetime","Returns the difference between two datetime expressions" +scalar,uuid,varchar,,,,"Returns a Universal Unique Identifier" +scalar,replace,varchar,,"varchar,varchar,varchar","Replaces all occurrences of a substring within a string" +scalar,inet_aton,int,,"varchar","Converts an IPv4 address to numeric value" +scalar,inet_ntoa,varchar,,"int","Converts numeric value to IPv4 address" +scalar,find_in_set,int,,"varchar,varchar","Returns position of string within a comma-separated list" +scalar,format,varchar,,"decimal,int","Formats number to specified decimal places and adds thousand separators" +scalar,from_unixtime,datetime,,"int","Converts Unix timestamp to datetime" +scalar,hex,varchar,,"decimal_or_string","Returns hexadecimal representation of a decimal or string value" +scalar,unhex,varchar,,"varchar","Converts hexadecimal value to string" +scalar,instr,int,,"varchar,varchar","Returns position of first occurrence of substring in string" +scalar,lcase,varchar,,"varchar","Synonym for LOWER()" +scalar,left,varchar,,"varchar,int","Returns the leftmost number of characters from string" +scalar,right,varchar,,"varchar,int","Returns the rightmost number of characters from string" +scalar,lpad,varchar,,"varchar,int,varchar","Left-pads string with specified characters to certain length" +scalar,rpad,varchar,,"varchar,int,varchar","Right-pads string with specified characters to certain length" +scalar,ltrim,varchar,,"varchar","Removes leading spaces from string" +scalar,rtrim,varchar,,"varchar","Removes trailing spaces from string" +scalar,power,decimal,,"decimal,decimal","Returns the value of number raised to specified power" +scalar,quote,varchar,,"varchar","Escapes string and adds single quotes" +scalar,repeat,varchar,,"varchar,int","Repeats a string specified number of times" +scalar,reverse,varchar,,"varchar","Reverses the characters in a string" +scalar,soundex,varchar,,"varchar","Returns soundex string of given string" +scalar,space,varchar,,"int","Returns string of specified number of spaces" +scalar,truncate,decimal,,"decimal,int","Truncates number to specified number of decimal places" +scalar,weekday,int,,"date","Returns weekday index (0=Monday, 6=Sunday)" +scalar,yearweek,int,,"date","Returns year and week number" +scalar,now,datetime,,,,"Synonym for CURRENT_TIMESTAMP()" +scalar,dayname,varchar,,"date","Returns name of weekday" +scalar,monthname,varchar,,"date","Returns name of month" +scalar,quarter,int,,"date","Returns quarter from date (1 to 4)" +scalar,week,int,,"date","Returns week number" +aggregate,count,int,,"any","Returns the number of rows in a group" +aggregate,sum,decimal/int,,"any","Returns the sum of values in a group" +aggregate,min,any,,"any","Returns the minimum value in a group" +aggregate,max,any,,"any","Returns the maximum value in a group" +aggregate,group_concat,varchar,,"any","Returns a concatenated string from a group" +aggregate,std,decimal,,"any","Returns the population standard deviation" +aggregate,variance,decimal,,"any","Returns the population variance" +aggregate,bit_and,int,,"int","Returns the bitwise AND of all bits in a group" +aggregate,bit_or,int,,"int","Returns the bitwise OR of all bits in a group" +aggregate,bit_xor,int,,"int","Returns the bitwise XOR of all bits in a group" +aggregate,json_arrayagg,json,,"any","Aggregates result set as JSON array" +aggregate,json_objectagg,json,,"varchar,any","Aggregates result set as JSON object" diff --git a/ibis-server/tests/routers/v3/connector/mysql/test_functions.py b/ibis-server/tests/routers/v3/connector/mysql/test_functions.py index e18afbb80..dacdd3124 100644 --- a/ibis-server/tests/routers/v3/connector/mysql/test_functions.py +++ b/ibis-server/tests/routers/v3/connector/mysql/test_functions.py @@ -1,4 +1,5 @@ import base64 +import os import orjson import pytest @@ -8,6 +9,7 @@ from app.main import app from tests.conftest import DATAFUSION_FUNCTION_COUNT, file_path from tests.routers.v3.connector.mysql.conftest import base_url +from tests.util import FunctionCsvParser, SqlTestGenerator manifest = { "catalog": "my_catalog", @@ -57,14 +59,14 @@ def test_function_list(): response = client.get(url=f"{base_url}/functions") assert response.status_code == 200 result = response.json() - assert len(result) == DATAFUSION_FUNCTION_COUNT + 35 + assert len(result) == DATAFUSION_FUNCTION_COUNT + 25 the_func = next(filter(lambda x: x["name"] == "abs", result)) assert the_func == { "name": "abs", "description": "Returns the absolute value of a number", "function_type": "scalar", "param_names": None, - "param_types": None, + "param_types": "int", "return_type": "int", } @@ -107,3 +109,18 @@ def test_aggregate_function(manifest_str: str, connection_info): "data": [[1]], "dtypes": {"col": "int64"}, } + + def test_functions(manifest_str: str, connection_info): + csv_parser = FunctionCsvParser(os.path.join(function_list_path, "mysql.csv")) + sql_generator = SqlTestGenerator("mysql") + for function in csv_parser.parse(): + sql = sql_generator.generate_sql(function) + response = client.post( + url=f"{base_url}/query", + json={ + "connectionInfo": connection_info, + "manifestStr": manifest_str, + "sql": sql, + }, + ) + assert response.status_code == 200 diff --git a/ibis-server/tests/util/sql_generator.py b/ibis-server/tests/util/sql_generator.py index 84e7d5303..2548ddf2f 100644 --- a/ibis-server/tests/util/sql_generator.py +++ b/ibis-server/tests/util/sql_generator.py @@ -26,6 +26,8 @@ def _get_generator(self): return BigQuerySqlGenerator() if self.dialect == "postgres": return PostgresSqlGenerator() + if self.dialect == "mysql": + return MySqlGenerator() if self.dialect == "mssql": return MSSqlGenerator() raise NotImplementedError(f"Unsupported dialect: {self.dialect}") @@ -154,6 +156,18 @@ def generate_window_sql(self, function: Function) -> str: """ +class MySqlGenerator(SqlGenerator): + def generate_aggregate_sql(self, function: Function) -> str: + sample_args = self.generate_sample_args(function.param_types) + formatted_args = ", ".join(sample_args) + return f"SELECT {function.name}({formatted_args})" + + def generate_scalar_sql(self, function: Function) -> str: + args = self.generate_sample_args(function.param_types) + formatted_args = ", ".join(args) + return f"SELECT {function.name}({formatted_args})" + + class MSSqlGenerator(SqlGenerator): def generate_aggregate_sql(self, function: Function) -> str: sample_args = self.generate_sample_args(function.param_types)