forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64a80f1
commit 3f011eb
Showing
26 changed files
with
650 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ATTACH DATABASE INFORMATION_SCHEMA | ||
ENGINE = Memory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/home/syz/ClickHouse/store/5ab/5abc80be-7165-462e-9e28-94d4467dd408/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ATTACH DATABASE _ UUID '5abc80be-7165-462e-9e28-94d4467dd408' | ||
ENGINE = Atomic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ATTACH DATABASE information_schema | ||
ENGINE = Memory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/home/syz/ClickHouse/store/99a/99a3fa29-6efd-4622-b822-ba63a202d9f4/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ATTACH DATABASE _ UUID '99a3fa29-6efd-4622-b822-ba63a202d9f4' | ||
ENGINE = Atomic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<!-- This file was generated automatically. | ||
Do not edit it: it is likely to be discarded and generated again before it's read next time. | ||
Files used to generate this file: | ||
config.xml --> | ||
|
||
<!-- Config that is used when server is run without config file. --> | ||
<clickhouse> | ||
<logger> | ||
<level>trace</level> | ||
<console>true</console> | ||
</logger> | ||
|
||
<http_port>8123</http_port> | ||
<tcp_port>9000</tcp_port> | ||
<mysql_port>9004</mysql_port> | ||
|
||
<path>./</path> | ||
|
||
<mlock_executable>true</mlock_executable> | ||
|
||
<users> | ||
<default> | ||
<password/> | ||
|
||
<networks> | ||
<ip>::/0</ip> | ||
</networks> | ||
|
||
<profile>default</profile> | ||
<quota>default</quota> | ||
|
||
<access_management>1</access_management> | ||
<named_collection_control>1</named_collection_control> | ||
</default> | ||
</users> | ||
|
||
<profiles> | ||
<default/> | ||
</profiles> | ||
|
||
<quotas> | ||
<default/> | ||
</quotas> | ||
</clickhouse> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
DROP FUNCTION IF EXISTS ai_estimate_rows; | ||
|
||
CREATE FUNCTION imdb.ai_estimate_rows | ||
RETURNS UInt64 | ||
LANGUAGE PYTHON AS | ||
$code$ | ||
from iudf import IUDF | ||
from overload import overload | ||
from BayesCard.Evaluation.cardinality_estimation import test_inference_result | ||
|
||
class ai_estimate_rows(IUDF): | ||
@overload | ||
def process(sql): | ||
res = test_inference_result(sql) | ||
return res | ||
$code$; | ||
|
||
DROP FUNCTION IF EXISTS ai_estimate_rows; | ||
|
||
select imdb.ai_estimate_rows('SELECT COUNT(*) FROM movie_info_idx WHERE id >= 713168 AND movie_id >= 2075341'); |
12 changes: 12 additions & 0 deletions
12
programs/server/user_defined/function_ai_estimate_rows.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CREATE FUCTION imdb.ai_estimate_rows TYPE SCALAR RETURNS UInt64 LANGUAGE PYTHON AS | ||
$code$ | ||
from iudf import IUDF | ||
from overload import overload | ||
from BayesCard.Evaluation.cardinality_estimation import test_inference_result | ||
|
||
class ai_estimate_rows(IUDF): | ||
@overload | ||
def process(sql): | ||
res = test_inference_result(sql) | ||
return res | ||
$code$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#pragma once | ||
#include <cstdint> | ||
#include <limits> | ||
#include <string> | ||
#include <string.h> | ||
#include <Common/BitHelpers.h> | ||
#include <IO/ReadBufferFromMemory.h> | ||
|
||
|
||
|
||
namespace DB::UDF | ||
{ | ||
constexpr auto SQL = "SQL"; | ||
constexpr auto PYTHON = "PYTHON"; | ||
constexpr auto SCALAR = "SCALAR"; | ||
constexpr auto AGGREGATE = "AGGREGATE"; | ||
constexpr auto ML = "ML"; | ||
using UDFFlags = uint32_t; | ||
enum class UDFLanguage | ||
{ | ||
Sql, | ||
Python | ||
}; | ||
enum class UDFFunctionType | ||
{ | ||
Scalar, | ||
Aggregate, | ||
ML | ||
}; | ||
static const char * Languages[2] = {SQL, PYTHON}; | ||
static const char * FunctionTypes[3] = {SCALAR, AGGREGATE, ML}; | ||
#define UDF_FIELD_TYPE GENMASK(28, 25) | ||
#define UDF_FIELD_LANG GENMASK(31, 29) | ||
#pragma clang diagnostic push | ||
#pragma clang diagnostic ignored "-Wshorten-64-to-32" | ||
static inline int getEnumValFromString(const char* enum_name, const char * const * arr, size_t n) { | ||
for (size_t i = 0; i < n; i++) { | ||
if (strcmp(arr[i], enum_name) == 0) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
} | ||
#pragma clang diagnostic pop | ||
#pragma clang diagnostic push | ||
#pragma clang diagnostic ignored "-Wold-style-cast" | ||
static inline enum UDFLanguage getLanguage(UDFFlags flags) { | ||
return static_cast<UDFLanguage>(FIELD_GET(UDF_FIELD_LANG, flags)); | ||
} | ||
static inline enum UDFFunctionType getFunctionType(UDFFlags flags) | ||
{ | ||
return static_cast<UDFFunctionType>(FIELD_GET(UDF_FIELD_TYPE, flags)); | ||
} | ||
static inline bool setFlag(UDFFlags &flags, const char *value, const char** enums, size_t n, uint64_t mask) { | ||
int z = getEnumValFromString(value, enums, n); | ||
if (z == -1) { | ||
return false; | ||
} | ||
flags |= FIELD_PREP(mask, z); | ||
return true; | ||
} | ||
#pragma clang diagnostic pop | ||
static inline const char * getLanguageStr(UDFLanguage language) { | ||
return Languages[to_underlying(language)]; | ||
} | ||
static inline const char * getFunctionTypeStr(UDFFunctionType func_type) | ||
{ | ||
return FunctionTypes[to_underlying(func_type)]; | ||
} | ||
static inline bool setFunctionType(UDFFlags &flags, const char *type) { | ||
return setFlag(flags, type, FunctionTypes, sizeof(FunctionTypes), UDF_FIELD_TYPE); | ||
} | ||
static inline bool setLangauge(UDFFlags &flags, const char *language) { | ||
return setFlag(flags, language, Languages, sizeof(Languages), UDF_FIELD_LANG); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.