### Run all example cases Source: https://github.com/alibaba/havenask/blob/main/aios/tools/hape/example/README.md Runs all example cases using a direct write table by default. Add --type offline to use a full table. ```bash /ha3_install/example/common/case.py run --case <样例名> ``` -------------------------------- ### Interact with cluster after example run Source: https://github.com/alibaba/havenask/blob/main/aios/tools/hape/example/README.md After an example finishes, the cluster is not deleted. Use this command to interact with it, e.g., check table status for the normal example. ```bash /ha3_install/example/common/case.py command --case normal --command "havenask gs table" ``` -------------------------------- ### Compile with Maven Source: https://github.com/alibaba/havenask/blob/main/aios/apps/facility/swift/client/java_client/README.md Run 'sudo mvn compile' to compile the project after installing protobuf 2.5 and modifying pom.xml paths. ```bash sudo mvn compile ``` -------------------------------- ### SELECT query examples Source: https://github.com/alibaba/havenask/wiki/SELECT Four example SELECT queries: selecting all columns, selecting with column alias, using DISTINCT, and a subquery with GROUP BY and WHERE filtering on the aggregated result. ```sql SELECT * FROM table; ``` ```sql SELECT f1, f2 AS ff FROM table; ``` ```sql SELECT DISTINCT f FROM table; ``` ```sql SELECT * FROM ( SELECT f1, count(*) AS num FROM t1 GROUP BY f1 ) tt WHERE tt.num > 100; ``` -------------------------------- ### 拉起swift集群 Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/petool/command.md 使用 `hape start swift` 拉起swift集群。 ```bash hape start swift ``` -------------------------------- ### processor_rule_config example Source: https://github.com/alibaba/havenask/wiki/data_table.json Configuration for data processing node count and concurrency. partition_count is the number of processing processes; recommended to be 1 for local index building. parallel_num is the concurrency for full data processing; the number of processing processes started during full build equals parallel_num * partition_count. Recommended to be 1 for local index building. ```json { "parallel_num" : 1, "partition_count" : 1 } ``` -------------------------------- ### Run with Advanced Configuration Source: https://github.com/alibaba/havenask/blob/main/aios/apps/facility/swift/client/java_client/README.md Run the client with advanced configuration for client_config, message_size, reader_config, and writer_config. The command includes zkPath, logConfigFile, useFollowerAdmin, and topic configurations. ```bash java -Xbootclasspath/a:./protobuf-java-2.5.0.jar:./jna-4.2.1.jar:./swift_client-1.1.0.jar com.alibaba.search.swift.perf.SwiftClientWriteReadPerf "zkPath=zfs://10.101.170.89:12181,10.101.170.90:12181,10.101.170.91:12181,10.101.170.92:12181,10.101.170.93:12181/swift/swift_service;logConfigFile=./swift_alog.conf;useFollowerAdmin=false" 10 topicName=sdd_test1 "topicName=sdd_test1;functionChain=HASH,hashId2partId##topicName=sdd_test2;;functionChain=HASH,hashId2partId" ``` -------------------------------- ### 获取子命令帮助 Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/petool/command.md 运行 `hape start -h` 查看start子命令的帮助,`hape start havenask -h` 查看特定参数的帮助。 ```bash hape start -h hape start havenask -h ``` -------------------------------- ### Multi-way UNION ALL Example Source: https://github.com/alibaba/havenask/wiki/UNION Merges three result sets with identical schema. This example uses UNION ALL to keep duplicate values. ```sql SELECT nid, brand, price, size FROM phone WHERE nid >= 3 AND nid <= 5 UNION ALL SELECT nid, brand, price, size FROM phone WHERE nid >= 6 AND nid <= 10 UNION ALL SELECT nid, brand, price, size FROM phone WHERE nid >= 30 AND nid <= 40 ``` -------------------------------- ### Package with Maven Source: https://github.com/alibaba/havenask/blob/main/aios/apps/facility/swift/client/java_client/README.md Run 'sudo mvn package' to package the project. Use '-Dmaven.test.skip=true' to skip unit tests. Set LD_LIBRARY_PATH to include the current directory. ```bash sudo mvn package ``` ```bash sudo mvn package -Dmaven.test.skip=true ``` ```bash export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./ ``` -------------------------------- ### processor_chain_config example with custom module Source: https://github.com/alibaba/havenask/wiki/data_table.json Example of a processing chain configuration. It shows how to configure clusters, document_processor_chain with a custom class (AnyClassName) and built-in TokenizeDocumentProcessor, and modules for loading dynamic libraries. The custom module requires module_name and module_path. ```json { "clusters" : [ "in0" ], "document_processor_chain" : [ { "class_name" : "AnyClassName", "module_name" : "example_module", "parameters" : { "param1" : "value1" } }, { "class_name" : "TokenizeDocumentProcessor", "module_name" : "", "parameters" : { } } ], "modules" : [ { "module_name" : "example_module", "module_path" : "libExample.so", "parameters" : { } } ] } ``` -------------------------------- ### 单独编译子项目:以 indexlib 为例 Source: https://github.com/alibaba/havenask/wiki/快速开始 以 indexlib 为例单独编译子项目。进入指定目录后,使用 scons install -j30 编译,-j 为编译线程数;执行 ut 时进入指定目录并使用 scons . -u -j20。 ```bash cd ~/havenask/aios/indexlib ## -j为编译线程数 scons install -j30 ## 执行ut,进入指定的目录 scons . -u -j20 ``` -------------------------------- ### Complete data_table.json configuration example Source: https://github.com/alibaba/havenask/wiki/data_table.json Full example of the $table_name_table.json file, showing the three main sections: processor_chain_config, processor_config, and processor_rule_config. processor_chain_config defines data processing logic, processor_config sets thread count and queue size, processor_rule_config sets node count and concurrency. ```json { "processor_chain_config" : [ { "clusters" : [ "in0" ], "document_processor_chain" : [ { "class_name" : "TokenizeDocumentProcessor", "module_name" : "", "parameters" : { } } ], "modules" : [ ] } ], "processor_config" : { "processor_queue_size" : 2000, "processor_thread_num" : 10 }, "processor_rule_config" : { "parallel_num" : 1, "partition_count" : 1 } } ``` -------------------------------- ### Run SwiftClientWriteReadPerf Source: https://github.com/alibaba/havenask/blob/main/aios/apps/facility/swift/client/java_client/README.md Run the performance test client with required JARs on the bootclasspath. May encounter zk address errors or missing alog files. ```bash java -Xbootclasspath/a:./protobuf-java-2.5.0.jar:./jna-4.2.1.jar:./swift_client-1.1.0.jar com.alibaba.search.swift.perf.SwiftClientWriteReadPerf ``` -------------------------------- ### Two-way UNION ALL Example Source: https://github.com/alibaba/havenask/wiki/UNION Merges two result sets with identical schema (field names, types, and order). This example uses UNION ALL to keep duplicate values. ```sql SELECT nid, brand, price, size FROM phone WHERE nid < 5 UNION ALL SELECT nid, brand, price, size FROM phone WHERE nid > 5 ``` -------------------------------- ### HASH_JOIN Hint Example Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/query_grammar/sql_grammar/Hint.md Shows how to use the HASH_JOIN hint on tables to force hash join optimization. The hint is applied to tj_relation and tj_item_raw, and the two joins (1) and (2) are optimized to HashJoin. ```sql SELECT /*+ HASH_JOIN(tj_relation)*/ * FROM ( SELECT /*+ HASH_JOIN(tj_item_raw)*/ * FROM ( SELECT sum(tj_item.id) as sum0 FROM tj_item GROUP BY tj_item.id ) B JOIN tj_item_raw on B.sum0 = tj_item_raw.id --> (1) ) D JOIN tj_relation on D.sum0 = tj_relation.item_id --> (2) (1)(2)两个join会被优化为HashJoin ``` -------------------------------- ### Set JNA Temporary Directory Source: https://github.com/alibaba/havenask/blob/main/aios/apps/facility/swift/client/java_client/README.md Set the temporary directory for JNA. ```bash -Djna.tmpdir=/ssd/sdd/git/swift/swift_java_client/target/ #设置临时目录 ``` -------------------------------- ### PACK Index Configuration Example Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/indexes/inverted.md Configures a multi-field PACK index for TEXT fields, merging multiple fields into one index for combined retrieval. Supports optional term payload, doc payload, position, position payload, term frequency, bitmap, and adaptive bitmap settings. Requires all fields to be TEXT type and use the same analyzer unless index_analyzer is specified. ```json { "name": "pack_index", "index_type": "PACK", "index_config": { "index_fields": [ { "field_name": "subject", "boost": 200000 }, { "field_name": "company_name", "boost": 600000 }, { "field_name": "feature_value", "boost": 600000 }, { "field_name": "summary", "boost": 600000 } ], "index_params": { "term_payload_flag": "1", "doc_payload_flag": "1", "position_list_flag": "1", "position_payload_flag": "1", "term_frequency_flag": "1", "term_frequency_bitmap": "1", "high_frequency_dictionary": "bitmap1", "high_frequency_adaptive_dictionary": "df", "high_frequency_term_posting_type": "both", "index_analyzer": "simple_analyzer", "format_version_id": "1" }, "compress_type": "ZSTD" } } ``` -------------------------------- ### LOOKUP_JOIN Hint Example Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/query_grammar/sql_grammar/Hint.md Shows how to use the LOOKUP_JOIN hint on tables to force lookup join optimization. The hint is applied to tj_relation and tj_item_raw, and both joins (1) and (2) become LookupJoin. ```sql SELECT /*+ LOOKUP_JOIN(tj_relation)*/ * FROM ( SELECT /*+ LOOKUP_JOIN(tj_item_raw)*/ * FROM ( SELECT sum(tj_item.id) as sum0 FROM tj_item GROUP BY tj_item.id ) B JOIN tj_item_raw on B.sum0 = tj_item_raw.id ---> (1) ) D JOIN tj_relation on D.sum0 = tj_relation.item_id ---> (2) (1)(2)两个join均为LookupJoin ``` -------------------------------- ### TEXT Index Configuration Example Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/indexes/inverted.md Configures a single-field TEXT index for a TEXT field, using a tokenizer to split text into terms and build an inverted chain per term. Supports optional term payload, doc payload, position, position payload, and term frequency. Only one field is allowed in index_fields. ```json { "name": "text_index", "index_type": "TEXT", "index_config": { "index_params": { "term_payload_flag": "1", "doc_payload_flag": "1", "position_payload_flag": "1", "position_list_flag": "1", "term_frequency_flag": "1" }, "index_fields": [ { "field_name": "title" } ], "compress_type": "ZSTD" } } ``` -------------------------------- ### Build index and start Havenask service Source: https://github.com/alibaba/havenask/blob/main/llm/README.md Copy the generated data file to the Havenask data directory and run the case script to write data into the engine. Requires Python 2.7 to start the service. ```shell cp ./llm.data /ha3_install/example/data/llm.data /ha3_install/example/common/case.py run --case llm ``` -------------------------------- ### GET /sql Source: https://github.com/alibaba/havenask/wiki/查询语法 Executes a SQL query against the Havenask cluster. The query is specified in the 'query' parameter and additional parameters are provided in the 'kvpair' parameter. ```APIDOC ## [GET] /sql ### Description Executes a SQL query against the Havenask cluster. The query is specified in the 'query' parameter and additional parameters are provided in the 'kvpair' parameter. ### Method GET ### Endpoint /sql ### Parameters #### Query Parameters - **query** (string) - Required - The SQL query to execute. - **kvpair** (string) - Optional - Additional parameters in key-value format, separated by semicolons. Example: `trace:INFO;formatType:json` ### Request Example ``` curl "ip:port/sql?query=SELECT brand, COUNT(*) FROM phone GROUP BY (brand)&&kvpair=trace:INFO;formatType:json" ``` ### Response #### Success Response (200) Returns the query results in the format specified by the `formatType` parameter in `kvpair` (e.g., JSON). #### Response Example (No explicit response example provided in the source.) ``` -------------------------------- ### Inverted index configuration JSON example Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/indexes/inverted.md Shows a complete inverted index configuration with multiple index types (NUMBER, STRING, TEXT, RANGE, PACK, PRIMARY_KEY64). Required fields are name, index_type, and index_fields; others are optional. For PACK indexes, index_fields can specify one or more fields; other types allow only one field. ```json { "indexes": [ { "name": "uint32", "index_type": "NUMBER", "index_config": { "index_fields": [ { "field_name": "uint32" } ], "compress_type": "SNAPPY" } }, { "name": "int8s", "index_type": "NUMBER", "index_config": { "index_fields": [ { "field_name": "int8s" } ], "compress_type": "ZSTD" } }, { "name": "string", "index_type": "STRING", "index_config": { "index_fields": [ { "field_name": "string" } ], "compress_type": "LZ4" } }, { "name": "strings", "index_type": "STRING", "index_config": { "index_fields": [ { "field_name": "strings" } ], "compress_type": "LZ4HC" } }, { "name": "text", "index_type": "TEXT", "index_config": { "index_fields": [ { "field_name": "text" } ], "compress_type": "ZLIB" } }, { "name": "texts", "index_type": "TEXT", "index_config": { "index_fields": [ { "field_name": "texts" } ], "compress_type": "ZLIB" } }, { "name": "range", "index_type": "RANGE", "index_config": { "index_fields": [ { "field_name": "int32" } ], "compress_type": "ZLIB" } }, { "name": "pack", "index_type": "PACK", "index_config": { "index_fields": [ { "field_name": "text", "boost": 100 }, { "field_name": "texts", "boost": 200 } ], "compress_type": "ZLIB" } }, { "name": "int8", "index_type": "PRIMARY_KEY64", "index_config": { "index_fields": [ { "field_name": "int8" } ] } } ] } ``` -------------------------------- ### processor_config example Source: https://github.com/alibaba/havenask/wiki/data_table.json Configuration for data processing thread count and queue size. processor_thread_num controls the number of threads; more threads speed up processing if CPU resources are sufficient. processor_queue_size is the queue size; when full, no new data is read. ```json { "processor_queue_size" : 2000, "processor_thread_num" : 10 } ``` -------------------------------- ### JNA Debug Load Source: https://github.com/alibaba/havenask/blob/main/aios/apps/facility/swift/client/java_client/README.md Enable JNA debug to show loaded shared objects. ```bash -Djna.debug_load=true #显示加载的so ``` -------------------------------- ### SELECT syntax format Source: https://github.com/alibaba/havenask/wiki/SELECT Shows the grammar for the SELECT statement in Havenask, including optional clauses for DISTINCT, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT, and OFFSET. The projectItem definition allows expressions with optional column aliases and table alias wildcards. ```sql SELECT: SELECT [ DISTINCT ] { * | projectItem [, projectItem ]* } FROM tableExpression [ WHERE booleanExpression ] [ GROUP BY { groupItem [, groupItem ]* } ] [ ORDER BY { orderByItem [, OrderByItem ]* }] [ HAVING booleanExpression ] [ LIMIT number] [ OFFSET number] projectItem: expression [ [ AS ] columnAlias ] | tableAlias . * ``` -------------------------------- ### 启动进程 process_starter.sh Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/petool/problem.md 执行 process_starter.sh 脚本以重启进程,需在后台运行(&)。 ```bash bash /process_starter.sh & ``` -------------------------------- ### 启动 bs startjob 并传入实时配置 Source: https://github.com/alibaba/havenask/wiki/实时功能使用文档 用于构建实时索引,通过 --realtimeInfo 传入 Kafka 数据源参数。需先拉起 Kafka 集群并创建 topic,且 cluster 配置中需设置 "realtime": true 并添加 processor 配置。 ```bash /home/havenask/havenask/ha3_install/usr/local/bin/bs startjob -c /home/havenask/havenask/example/cases/realtime/config/offline_config -n in0 -j local -m full -d /home/havenask/havenask/example/data/test.data -w /home/havenask/havenask/example/cases/realtime/workdir -i ./runtimedata -p 1 --documentformat=ha3 --realtimeInfo="{ \"realtime_mode\":\"realtime_service_rawdoc_rt_build_mode\", \"data_table\" : \"in0\", \"type\":\"plugin\", \"module_name\":\"kafka\", \"module_path\":\"libbs_raw_doc_reader_plugin.so\", \"topic_name\":\"quickstart-events\", \"bootstrap.servers\":\"localhost:9092\", \"src_signature\":\"16113477091138423397\", \"realtime_process_rawdoc\": \"true\" } " ``` -------------------------------- ### 查找进程启动脚本 process_starter.sh Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/petool/problem.md 在手动进程重启方法中,使用 find 命令定位 process_starter.sh 脚本。 ```bash find -name process_starter.sh ``` -------------------------------- ### 执行编译指令:configure 和 build Source: https://github.com/alibaba/havenask/wiki/快速开始 在容器内执行编译指令。如果报 "fatal error: Killed signal terminated program cc1plus" 错误,是由于编译机器内存不足导致的,请 build 时减少线程数(如:./build 5)。 ```bash ./configure ./build ``` -------------------------------- ### TaobaoSpRerankTvf example Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/query_grammar/custom_function/tvf/buildin_tvf.md Example usage of taobaoSpRerankTvf with group_fields='trigger_type', actual_group_field_values='1;11', quota_num='100', sort_fields='-final_score'. ```sql simpleRerankTvf('trigger_type', '1;11', '100', '-final_score', (sql) ) ``` -------------------------------- ### simpleRerankTvf example Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/query_grammar/custom_function/tvf/buildin_tvf.md Example usage of simpleRerankTvf with group_fields='trigger_type', actual_group_field_values='1;11', quota_num='100', sort_fields='-final_score', need_makeup='t'. ```sql simpleRerankTvf('trigger_type', '1;11', '100', '-final_score', 't', (sql) ) ``` -------------------------------- ### WHERE with AND and IN Examples Source: https://github.com/alibaba/havenask/wiki/WHERE Two example queries: one using AND to combine conditions, another using IN to filter on a set of values. ```sql SELECT * FROM table WHERE f1 > 10 AND f2 < 5 ``` ```sql SELECT * FROM table WHERE id IN (5, 6, 7, 8, 9) ``` -------------------------------- ### 修复docker.sock权限问题 Source: https://github.com/alibaba/havenask/wiki/Hape问题排查 当docker命令因权限问题无法执行时,使用此命令修改docker.sock的权限,允许非root用户访问。 ```bash sudo chmod 666 /var/run/docker.sock ``` -------------------------------- ### 创建容器:拉取镜像并运行 create_container.sh Source: https://github.com/alibaba/havenask/wiki/快速开始 单机模式下,通过镜像启动 Havenask 引擎的第一步。需要先克隆仓库并进入 docker 目录,然后拉取运行时镜像并执行 create_container.sh 创建容器,其中 CONTAINER_NAME 为指定的容器名。 ```bash git clone git@github.com:alibaba/havenask.git cd havenask/docker docker pull havenask/ha3_runtime:0.3.0 ./create_container.sh havenask/ha3_runtime:0.3.0 ``` -------------------------------- ### collectOutputInfo interface example in C++ Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/query_grammar/custom_function/tvf/buildin_tvf.md Shows the SummaryOutputInfoType typedef and an example implementation of collectOutputInfo that returns a vector of field name and type pairs. ```cpp typedef std::vector> SummaryOutputInfoType; virtual SummaryOutputInfoType collectOutputInfo(); // example: SummaryOutputInfoType PostFeeSummaryExtractor::collectOutputInfo() { if (_dstSummaryField.empty()) { return {}; } return {make_pair(_dstSummaryField, "string")}; // [(字段名,类型)] } ``` -------------------------------- ### 启动容器:创建开发容器 Source: https://github.com/alibaba/havenask/wiki/快速开始 下载代码后,进入 docker 目录并执行 create_container.sh 创建开发容器,其中 DOCKER_NAME 为指定的容器名。 ```bash cd ~/havenask/docker ./create_container.sh havenask/ha3_dev:0.3.0 ``` -------------------------------- ### OneSummaryTvf SQL query example Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/query_grammar/custom_function/tvf/buildin_tvf.md Example SQL query using the tpp TVF with kvpair, empty query clause, and a SELECT statement filtering by ha_in. ```sql tpp( 'dl:tpp_default', // kvpair '', // query子句,一般不需要 ( // sql SELECT * FROM mainse_summary_summary_ WHERE ha_in(nid, '620598126603|619969492623') ) ) ``` -------------------------------- ### 创建容器并拉取镜像 Source: https://github.com/alibaba/havenask/blob/main/README.md 下载创建容器的脚本,拉取运行时镜像,并创建指定名称的容器。 ```bash wget https://github.com/alibaba/havenask/releases/download/v1.2.0/create_container.sh docker pull registry.cn-hangzhou.aliyuncs.com/havenask/ha3_runtime:latest ./create_container.sh registry.cn-hangzhou.aliyuncs.com/havenask/ha3_runtime:latest ``` -------------------------------- ### enableShuffleTvf usage example Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/query_grammar/custom_function/tvf/buildin_tvf.md Example of using enableShuffleTvf to run the inner query on the qrs node. The inner SQL selects brand and size from the phone table. ```sql select * from table ( enableShuffleTvf((SELECT brand, size FROM phone)) ) ``` -------------------------------- ### vector_score usage examples Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/query_grammar/custom_function/udf/intro.md Two example SQL queries using vector_score with MATCHINDEX. The first uses the default score, the second specifies a default score of 1000.0. ```sql SELECT vector_score('vector_score') FROM phone where MATCHINDEX('vector_score', '0.57350874,0.20913178&&n=10') ``` ```sql SELECT vector_score('vector_score', 1000.0) FROM phone where MATCHINDEX('vector_score', '0.57350874,0.20913178&&n=10') ``` -------------------------------- ### ha_in usage example with output Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/query_grammar/custom_function/udf/intro.md Example SQL query using ha_in to retrieve records where nid is in the given list. The output shows the execution time and the matching nid values. ```sql select nid from mainse_excellent_search where ha_in(nid, '641999912989|577150359640|123456') ``` ```plaintext USE_TIME: 32.141ms, ROW_COUNT: 2 ------------------------------- TABLE INFO --------------------------- nid(int64) | 641999912989 | 577150359640 | ``` -------------------------------- ### rerankByQuotaTvf example with trigger_type Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/query_grammar/custom_function/tvf/buildin_tvf.md Example invocation of rerankByQuotaTvf grouping by trigger_type with values '1;11', quotas '100,200;100,300', reranking by ju_category_id, sorting by -final_score, and makeup enabled. Demonstrates the parameter format for multi-group configurations. ```sql rerankByQuotaTvf('trigger_type', '1;11', '100,200;100,300', 'ju_category_id', '-final_score', '50', '15', 't;t', (sql) ) ``` -------------------------------- ### 查询数据 Source: https://github.com/alibaba/havenask/blob/main/README.md 使用 sql_query.py 查询 in0 表中的所有数据。 ```bash /ha3_install/sql_query.py --query "select * from in0" ``` -------------------------------- ### 写入数据 Source: https://github.com/alibaba/havenask/blob/main/README.md 使用 sql_query.py 插入一条数据到 in0 表。 ```bash /ha3_install/sql_query.py --query "insert into in0 (createtime,hits,id,title,subject)values(1,2,4,'测试', '测试')" ``` -------------------------------- ### unpackMultiValue usage example Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/query_grammar/custom_function/tvf/buildin_tvf.md Example of using unpackMultiValue to flatten the desc, price, and size fields from the phone table where size > 5.5. Note that flattened multi-value fields will contain only 0 or 1 values, and too many fields can cause Cartesian product explosion. ```sql select * from table ( unpackMultiValue('desc,price,size', (SELECT desc, price, size FROM phone where size > 5.5)) ) ``` -------------------------------- ### 构建索引并拉起引擎 Source: https://github.com/alibaba/havenask/wiki/实时功能使用文档 快速开始实时功能:先修改 realtime_info.json 中的 topic_name 和 bootstrap.servers,然后依次执行构建和启动命令。 ```bash cd ~/havenask/example python build_demo_data.py /ha3_install/ realtime python start_demo_searcher.py /ha3_install/ realtime ``` -------------------------------- ### 获取默认hippo config - hape get default-hippo-config Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/petool/scene.md 渲染后的默认hippo config内容可以用get命令获取,分别指定searcher和qrs角色。 ```bash hape get default-hippo-config -r searcher hape get default-hippo-config -r qrs ``` -------------------------------- ### 启动集群 Source: https://github.com/alibaba/havenask/wiki/Hape快速开始 执行start命令启动集群,目标会被保存并在后台异步执行。可通过ps命令确认domain daemon已启动。 ```bash python bin/hape_cmd.py start --role all --config conf/generated//_hape_config ## 可以通过以下指令确定domain daemon已经被启动了 ps -aux | grep domain_daemon ``` -------------------------------- ### 初始化集群配置 Source: https://github.com/alibaba/havenask/wiki/Hape快速开始 使用hape_cmd.py的init子命令初始化集群配置,生成配置到conf/generated/。 ```bash python bin/hape_cmd.py init --iplist --domain_name --index ``` -------------------------------- ### WHERE with AND and comparison operators Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/query_grammar/sql_grammar/WHERE.md Example query using AND with comparison operators (>, <) in the WHERE clause. ```sql SELECT * FROM table WHERE f1 > 10 AND f2 < 5 ``` -------------------------------- ### SQL预热配置 - iquan_warmup_config Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/petool/scene.md 在sql.json中添加此字段以配置SQL预热,避免引擎拉起初次查询时因预热而慢。warmup线程数默认值为2,建议设大些;warmup_file_path为业务预热SQL文件,需放到sql.json同级目录。 ```json "iquan_warmup_config": { "thread_number" : 2, // warmup线程数,默认值为2个线程,建议设大些, "warmup_file_path": "warmup_sql.txt" // 业务预热SQL文件,放到sql.json同级目录 } ``` -------------------------------- ### WHERE with IN operator Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/query_grammar/sql_grammar/WHERE.md Example query using the IN operator to filter rows where id matches a list of values. ```sql SELECT * FROM table WHERE id IN (5, 6, 7, 8, 9) ``` -------------------------------- ### 登录容器 Source: https://github.com/alibaba/havenask/blob/main/README.md 通过生成的脚本登录到已创建的容器。 ```bash .//sshme ``` -------------------------------- ### GET /sqlClientInfo Source: https://github.com/alibaba/havenask/wiki/查询语法 Retrieves information about the tables and functions registered in the cluster. This is useful for discovering available data sources and functions. ```APIDOC ## [GET] /sqlClientInfo ### Description Retrieves information about the tables and functions registered in the cluster. This is useful for discovering available data sources and functions. ### Method GET ### Endpoint /sqlClientInfo ### Parameters None ### Request Example ``` curl "ip:port/sqlClientInfo" ``` ### Response #### Success Response (200) Returns a list of registered tables and functions. #### Response Example (No explicit response example provided in the source.) ``` -------------------------------- ### CASE-WHEN as Condition Expression (Direct) Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/query_grammar/sql_grammar/CASE-WEHN.md Uses CASE-WHEN directly in the WHERE clause as a condition expression. This is valid when the CASE-WHEN result is compared to a value. ```SQL SELECT * FROM s_wmp_package_wave WHERE CASE WHEN warehouse_id=48 THEN warehouse_id WHEN warehouse_id=24 THEN id ELSE buyer_id END > 10 AND wave_status = 0 LIMIT 10; ``` -------------------------------- ### 创建表 Source: https://github.com/alibaba/havenask/blob/main/README.md 使用 hape 命令创建表,指定表名、schema 文件和分区数。 ```bash /ha3_install/hape create table -t in0 -s /ha3_install/example/cases/normal/in0_schema.json -p 1 ``` -------------------------------- ### GET /sqlClientInfo Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/query_grammar/query.md Retrieves the cluster registration information, including registered tables and functions. This endpoint is used to inspect the available data sources and functions in the cluster. ```APIDOC ## [GET] /sqlClientInfo ### Description Retrieves the cluster registration information, including registered tables and functions. This endpoint is used to inspect the available data sources and functions in the cluster. ### Method GET ### Endpoint /sqlClientInfo ### Parameters None ### Request Example ``` curl ":/sqlClientInfo" ``` ### Response #### Success Response Returns the cluster registration information, including registered tables and functions. #### Response Example (Not provided in source) ``` -------------------------------- ### 重启swift集群 Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/petool/command.md 使用 `hape restart swift` 重启swift集群。 ```bash hape restart swift ``` -------------------------------- ### loadDoc() 函数:使用 XMLHttpRequest 获取 /modify Source: https://github.com/alibaba/havenask/blob/main/aios/apps/facility/build_service/build_service/web_toolkit/base/test/testdata/demo.html 当页面加载时,此函数创建一个 XMLHttpRequest 对象,向 '/modify' 发送 GET 请求,并在响应就绪且状态为 200 时,将响应文本插入到 id 为 'demo' 的元素中。 ```javascript function loadDoc() { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("demo").innerHTML = this.responseText; } }; xhttp.open("GET", "/modify", true); xhttp.send(); } ``` -------------------------------- ### enableShuffleTvf prototype Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/query_grammar/custom_function/tvf/buildin_tvf.md Shows the function signature for enableShuffleTvf, which forces the TVF above it to run on the qrs node instead of being pushed down to searcher. For example, wrapping rankTvf with this prevents pushdown. ```sql enableShuffleTvf((sql)) ``` -------------------------------- ### 启动 Havenask 服务 Source: https://github.com/alibaba/havenask/blob/main/README.md 使用 hape 命令启动 Havenask 服务。 ```bash /ha3_install/hape start havenask ``` -------------------------------- ### Clone models from Hugging Face Source: https://github.com/alibaba/havenask/blob/main/llm/README.md Downloads the ChatGLM-6b and text2vec-large-chinese models to the local havenask directory using Git LFS. Requires Git LFS installed. ```shell cd ~/havenask git clone https://huggingface.co/THUDM/chatglm-6b git clone https://huggingface.co/GanymedeNil/text2vec-large-chinese ``` -------------------------------- ### HASH_JOIN Hint 示例 Source: https://github.com/alibaba/havenask/wiki/Hint 在子查询和外部查询中指定 HASH_JOIN Hint,使两个 JOIN 操作优化为 HashJoin。Hint 作用于表,优先作为内层 build 表。 ```sql SELECT /*+ HASH_JOIN(tj_relation)*/ * FROM ( SELECT /*+ HASH_JOIN(tj_item_raw)*/ * FROM ( SELECT sum(tj_item.id) as sum0 FROM tj_item GROUP BY tj_item.id ) B JOIN tj_item_raw on B.sum0 = tj_item_raw.id --> (1) ) D JOIN tj_relation on D.sum0 = tj_relation.item_id --> (2) (1)(2)两个join会被优化为HashJoin ``` -------------------------------- ### bm25_score usage examples Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/query_grammar/custom_function/udf/intro.md SQL queries using bm25_score with and without an index name. The first query scores all matched indexes, the second only scores the 'default1' index. ```sql SELECT bm25_score() FROM phone where MATCHINDEX('default1', '阿里') AND MATCHINDEX('default2', '阿里') SELECT bm25_score('default1') FROM phone where MATCHINDEX('default1', '阿里') AND where MATCHINDEX('default2', '阿里') ``` -------------------------------- ### 重启havenask集群 Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/petool/command.md 使用 `hape restart havenask` 重启havenask集群。 ```bash hape restart havenask ``` -------------------------------- ### tfidf_score usage examples Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/query_grammar/custom_function/udf/intro.md SQL queries using tfidf_score with and without an index name. The first query scores all matched indexes, the second only scores the 'default1' index. ```sql SELECT tfidf_score() FROM phone where MATCHINDEX('default1', '阿里') AND MATCHINDEX('default2', '阿里') SELECT tfidf_score('default1') FROM phone where MATCHINDEX('default1', '阿里') AND where MATCHINDEX('default2', '阿里') ``` -------------------------------- ### Summary查询示例:叠加AND条件 Source: https://github.com/alibaba/havenask/wiki/Summary查询 在确保查询条件中含有pk字段后,可以通过AND语句叠加其他条件对召回的宝贝进行筛选。此示例在IN条件基础上增加price < 2000的过滤。 ```sql SELECT brand, price FROM phone_summary_ WHERE nid IN (7, 8, 9) AND price < 2000 ``` -------------------------------- ### 启用动态参数的 SQL 查询示例 Source: https://github.com/alibaba/havenask/wiki/动态参数 在 SQL 中使用 '?' 作为占位符,通过 kvpair 传入具体参数值。动态参数只能替换值,不支持关键字或字段替换。 ```sql SELECT i1, cast(? as bigint) FROM t1 WHERE (i2 > 5 AND d3 < 10.1) OR s5 = ? ``` ```text kvpair=...; iquan.plan.prepare.level:jni.post.optimize; dynamic_params:[[10, "str5"]]; ...; ``` -------------------------------- ### CASE-WHEN as Condition Expression (Subquery) Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/query_grammar/sql_grammar/CASE-WEHN.md Uses CASE-WHEN inside a subquery to compute 'aa', then filters on that computed column in the outer query. This is a valid way to use CASE-WHEN as a condition expression. ```SQL SELECT * FROM ( SELECT CASE WHEN warehouse_id=48 THEN warehouse_id WHEN warehouse_id=24 THEN id ELSE wave_status END AS aa FROM s_wmp_package_wave WHERE wave_status = 0 ) t WHERE t.aa > 10 LIMIT 10; ``` -------------------------------- ### Build knowledge base with embed_files.py Source: https://github.com/alibaba/havenask/blob/main/llm/README.md Process data files (markdown or PDF) to generate a Havenask engine data file. The example clones the Havenask wiki and ignores .git and english directories. ```shell git clone https://github.com/alibaba/havenask.wiki.git python -m script.embed_files -f havenask.wiki -o ./llm.data -i .git,english ``` -------------------------------- ### 全局配置 global.conf 示例 Source: https://github.com/alibaba/havenask/wiki/Hape配置详解 hape init 子命令生成的全局配置文件,一般无需修改。包含 hape-worker、hape-admin、container-service 和 dfs 配置段。dfs 类型支持 docker 和 local,默认为 local。 ```ini [hape-worker] worker-name-prefix = havenask logging-conf = package/worker_logging.conf workdir = /home/xxx/havenask/hape/workers [hape-admin] daemon-process-interval-sec = 1 logging-conf = /home/xxx/havenask/hape/conf/generated/shop/shop_hape_config/logging/admin_logging.conf enable-daemon-debug = False enable-cmd-debug = False workdir = /home/xxx/havenask/hape/admin [container-service] type = docker [dfs] type = local ``` -------------------------------- ### SQL预热文件格式 - warmup_sql.txt Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/petool/scene.md warmup_sql.txt的格式如下,可以填写业务上需要预热的query语句。 ```json { "sqls":[ "SELECT i1, min(i2) FROM t1 GROUP BY i1" ] } ``` -------------------------------- ### LOOKUP_JOIN Hint 示例 Source: https://github.com/alibaba/havenask/wiki/Hint 在子查询和外部查询中指定 LOOKUP_JOIN Hint,使两个 JOIN 操作优化为 LookupJoin。Hint 作用于表,优先作为内层 build 表。 ```sql SELECT /*+ LOOKUP_JOIN(tj_relation)*/ * FROM ( SELECT /*+ LOOKUP_JOIN(tj_item_raw)*/ * FROM ( SELECT sum(tj_item.id) as sum0 FROM tj_item GROUP BY tj_item.id ) B JOIN tj_item_raw on B.sum0 = tj_item_raw.id ---> (1) ) D JOIN tj_relation on D.sum0 = tj_relation.item_id ---> (2) (1)(2)两个join均为LookupJoin ``` -------------------------------- ### UNION Syntax Source: https://github.com/alibaba/havenask/wiki/UNION Defines the grammar for UNION and UNION ALL operations. UNION ALL retains duplicates, while UNION performs deduplication (equivalent to UNION ALL + DISTINCT) and is less efficient. Mixing UNION and UNION ALL in a multi-way UNION is not supported. ```sql select_statement UNION [ALL] select_statement [UNION [ALL] select_statement]; ``` -------------------------------- ### 查看swift服务的serviceZk地址 Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/petool/clustermode.md 查看swift服务的serviceZk地址。 ```bash hape gs swift ``` -------------------------------- ### CASE WHEN as Output Expression Source: https://github.com/alibaba/havenask/wiki/CASE-WEHN Uses CASE WHEN as an output expression in a SELECT clause. The example checks warehouse_id values and returns corresponding columns, with ELSE returning wave_status. The query filters wave_status = 0 and limits to 10 rows. ```sql SELECT CASE WHEN warehouse_id=48 THEN warehouse_id WHEN warehouse_id=24 THEN id ELSE wave_status END AS aa FROM s_wmp_package_wave WHERE wave_status = 0 LIMIT 10; ``` -------------------------------- ### 多字段排序示例 Source: https://github.com/alibaba/havenask/wiki/ORDER-BY 按 size 和 price 字段降序排序,先按 size 排序,再按 price 排序。 ```sql SELECT nid, brand, price, size FROM phone ORDER BY size DESC, price DESC LIMIT 1000 ``` -------------------------------- ### 启动容器 Source: https://github.com/alibaba/havenask/wiki/快速开始-1.0.0-beta 创建开发容器。 ```bash cd ~/havenask/docker/havenask ./create_container.sh registry.cn-hangzhou.aliyuncs.com/havenask/ha3_dev:1.0.0-beta2 ``` -------------------------------- ### GROUP BY GROUPING SETS example Source: https://github.com/alibaba/havenask/wiki/GROUPING-SETS Shows a typical grouping sets query that groups by brand, size, and the entire table to compute price sums. The output uses default values (empty string and 0.0) for invalid columns in each grouping subset. ```sql SELECT brand,size,SUM(price) AS sp FROM phone GROUP BY GROUPING SETS ((brand),(size),()) ``` ```text BRAND SIZE sp "", 0.0, 32936 (所有手机总价) "", 1.4, 169 (各种尺寸的价格统计) "", 4.7, 7897 "", 5.0, 899 "", 5.5, 14684 "", 5.6, 5688 "", 5.9, 3599 "Huawei", 0, 7987 (各种品牌的价格统计) "Meizu", 0, 1299 "Nokia", 0, 169 "Xiaomi", 0, 899 "OPPO", 0, 2999 "Samsung", 0, 5688 "Apple", 0, 13895 ``` -------------------------------- ### 使用 curl 执行 SQL 查询 Source: https://github.com/alibaba/havenask/wiki/查询语法 通过 curl 调用 /sql 接口执行 SQL 查询。注意 kvpair 和 && 之间以及 kvpair 各项之间不允许有空格,否则解析无效。 ```bash curl "ip:port/sql?query=SELECT brand, COUNT(*) FROM phone GROUP BY (brand)&&kvpair=trace:INFO;formatType:json" ``` -------------------------------- ### 创建 Docker 容器 Source: https://github.com/alibaba/havenask/blob/main/llm/README.md 使用 create_container.sh 脚本创建 Havenask 容器,指定镜像 registry.cn-hangzhou.aliyuncs.com/havenask/ha3_runtime:latest。 ```shell cd ~/havenask/docker ./create_container.sh havenask registry.cn-hangzhou.aliyuncs.com/havenask/ha3_runtime:latest ``` -------------------------------- ### 创建全量表 Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/petool/command.md 使用 `hape create table` 创建全量表,需要指定表名、分片数、schema路径和全量数据文件路径。 ```bash hape create table -t in1 -p 1 -s /ha3_install/example/cases/normal/in0_schema.json -f /ha3_install/example/cases/normal/test.data ``` -------------------------------- ### 验证 HDFS 配置 fs_util ls Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/petool/problem.md 用于验证多机模式下 HDFS 配置是否成功,需设置 JAVA_HOME、HADOOP_HOME 环境变量并指定数据目录。 ```bash JAVA_HOME= HADOOP_HOME= /ha3_install/usr/local/bin/fs_util ls ``` -------------------------------- ### 集群资源&参数调整(1.1.0之前)- hape restart Source: https://github.com/alibaba/havenask/blob/main/docs/havenask_docs/sql/petool/scene.md 1.1.0之前需要重启集群havenask/swift来应用资源或参数调整。 ```bash hape restart havenask/swift ```