SQL Functions

Singdata Lakehouse includes a rich built-in SQL function library covering numeric computation, string processing, time operations, complex types, aggregation and window analysis, as well as specialized functions for AI and analytics scenarios such as vector search and BITMAP audience segmentation.


Function Categories

Core Computation

CategoryDescription
OperatorsArithmetic, comparison, logical, and bitwise operators
Math FunctionsABS, ROUND, CEIL, FLOOR, POWER, LOG, and other numeric functions
Conditional FunctionsIF, IFF, CASE WHEN, COALESCE, NULLIF, NVL, and other conditional expressions
Type Conversion FunctionsCAST, TRY_CAST, and various type conversion functions

String and Regex

CategoryDescription
String FunctionsCONCAT, SUBSTR, TRIM, REPLACE, SPLIT, LENGTH, and more
Regex FunctionsREGEXP_LIKE, REGEXP_EXTRACT, REGEXP_REPLACE, and more
Encryption and Masking FunctionsMD5, SHA256, AES encryption/decryption, data masking
Hash FunctionsHASH, MURMUR_HASH, and other hash functions

Time and Date

CategoryDescription
Time FunctionsDATE_ADD, DATE_DIFF, DATE_FORMAT, CONVERT_TIMEZONE, CURRENT_TIMESTAMP, and more

Complex Types

CategoryDescription
ARRAY FunctionsARRAY_AGG, ARRAY_CONTAINS, EXPLODE, SORT_ARRAY, and more
MAP FunctionsMAP_KEYS, MAP_VALUES, MAP_CONTAINS_KEY, and more
STRUCT FunctionsSTRUCT construction and field access
JSON FunctionsJSON_VALUE, JSON_EXTRACT, JSON_OBJECT, JSON_ARRAY, and more
Higher-Order FunctionsTRANSFORM, FILTER, AGGREGATE, REDUCE, and other lambda functions

Aggregation and Window

CategoryDescription
Aggregate FunctionsCOUNT, SUM, AVG, MAX, MIN, PERCENTILE, CORR, and more
Window FunctionsROW_NUMBER, RANK, LAG, LEAD, SUM OVER, NTILE, and more

AI and Analytics

AI Functions are native AI capabilities in Singdata Lakehouse. They let you call large language models and embedding models directly in SQL — completing text understanding, vectorization, and content generation without leaving the data platform. All AI functions take model as the first parameter, in the format 'endpoint:model_name' (configured via AI Gateway).

FunctionDescription
AI_COMPLETEGeneral LLM completion; supports custom prompts; suited for complex reasoning, code generation, and other custom scenarios; supports image input
AI_EMBEDDINGConvert text to high-dimensional vectors (ARRAY<FLOAT>); used for semantic search, RAG, recommendations, and clustering
AI_CLASSIFYClassify text or images into user-defined categories; no prompt writing required; supports 29+ languages
AI_EXTRACTExtract structured JSON from unstructured text or images by specified fields; no prompt writing required
AI_SENTIMENTSentiment analysis; returns positive / negative / neutral; supports multiple languages
AI_SUMMARIZEGenerate text summaries; supports max_words to control summary length
AI_TRANSLATEText translation; source language auto-detected; supports 20+ language pairs
AI_FIX_GRAMMARAutomatically fix grammar, spelling, and punctuation errors; supports Chinese, English, and mixed-language text
AI_MASKIdentify and mask PII sensitive information; replaces with [MASKED]; labels are user-defined
AI_SIMILARITYCompute cosine similarity between two text segments; returns a score in [0, 1]
AI_TRANSCRIBETranscribe audio files to plain text (ASR); supports Chinese, English, and other languages

Full documentation and examples: AI Functions Guide · AI Functions Overview · AI Gateway Configuration

CategoryDescription
Vector FunctionsVector distance computation (cosine_distance, l2_distance, etc.), vector similarity search
Search FunctionsFull-text search scoring functions; used with inverted indexes
BITMAP FunctionsBITMAP_AND, BITMAP_OR, BITMAP_CARDINALITY, and other audience segmentation and UV statistics functions

Database and System

CategoryDescription
Context FunctionsCURRENT_USER, CURRENT_DATABASE, VERSION, and other session information functions
Table FunctionsEXPLODE, GENERATE_SERIES, UNNEST, and other table-returning functions
File FunctionsVolume file operation functions
Partition FunctionsPartition pruning and partition metadata query functions

Other

CategoryDescription
GEO FunctionsGeospatial computation: distance, coordinate conversion, etc.
IP FunctionsIP address parsing, geolocation lookup, etc.
BIT FunctionsBIT_COUNT, SHIFTLEFT, SHIFTRIGHT, and other bitwise operation functions

DocumentDescription
Data TypesType descriptions to understand function input and output types
SQL Functions Usage GuideQuick function reference and usage tips for common scenarios
AI Functions (AI_COMPLETE / AI_EMBEDDING)Call LLMs and vector embeddings in SQL