Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] support Quantile Sketche #54569

Open
wants to merge 53 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
d4fa445
support dataSketches include Quantile Sketches、Theta Sketch、Frequency…
chenminghua8 Oct 22, 2024
cf082a9
fix format exception.
chenminghua8 Oct 23, 2024
2540ae9
fix format exception.
chenminghua8 Oct 24, 2024
02dc2b0
fix format exception.
chenminghua8 Oct 24, 2024
358b652
fix format exception.
chenminghua8 Oct 24, 2024
60f073e
Merge branch 'StarRocks:main' into support_dataSketches
chenminghua8 Oct 24, 2024
01a85d0
Merge branch 'StarRocks:main' into support_dataSketches
chenminghua8 Nov 24, 2024
6aff6a7
fix AggStateCombinatorTest fault
chenminghua8 Nov 24, 2024
c573071
fix AggStateCombinatorTest fault
chenminghua8 Nov 25, 2024
51e8596
Merge branch 'StarRocks:main' into support_dataSketches
chenminghua8 Nov 25, 2024
accf967
Merge branch 'StarRocks:main' into support_dataSketches
chenminghua8 Nov 26, 2024
e0257e9
Merge branch 'StarRocks:main' into support_dataSketches
chenminghua8 Dec 2, 2024
38b153e
add tests
chenminghua8 Dec 2, 2024
19d9389
add tests
chenminghua8 Dec 4, 2024
793cc6c
Merge branch 'StarRocks:main' into support_dataSketches
chenminghua8 Dec 4, 2024
8d337aa
Add test cases to improve code coverage
chenminghua8 Dec 4, 2024
643e868
Add test cases to improve code coverage
chenminghua8 Dec 4, 2024
6e0516b
Add test cases to improve code coverage
chenminghua8 Dec 4, 2024
707b4f1
support dataSketches include Quantile Sketches、Theta Sketch、Frequency…
chenminghua8 Oct 22, 2024
f8276df
fix format exception.
chenminghua8 Oct 23, 2024
7bde2bc
fix format exception.
chenminghua8 Oct 24, 2024
573ee8c
fix format exception.
chenminghua8 Oct 24, 2024
fab9f3f
fix format exception.
chenminghua8 Oct 24, 2024
cd3cba0
fix AggStateCombinatorTest fault
chenminghua8 Nov 24, 2024
b00773a
fix AggStateCombinatorTest fault
chenminghua8 Nov 25, 2024
aaae8aa
add tests
chenminghua8 Dec 2, 2024
2f092b1
add tests
chenminghua8 Dec 4, 2024
e4db576
Add test cases to improve code coverage
chenminghua8 Dec 4, 2024
cc875af
Add test cases to improve code coverage
chenminghua8 Dec 4, 2024
139ac86
Add test cases to improve code coverage
chenminghua8 Dec 4, 2024
ebaca8d
Fix aggregate_test test error due to using unused AnyValUtils
chenminghua8 Dec 5, 2024
ca4e313
Fix aggregate_test test error due to using unused AnyValUtils
chenminghua8 Dec 5, 2024
260d88b
Fix aggregate_test test error due to using unused AnyValUtils
chenminghua8 Dec 5, 2024
6d2dcf2
Fix other sketch nullptr and add ds_theta_count_distinct syntax
chenminghua8 Dec 8, 2024
499533f
Fix Clang format failling
chenminghua8 Dec 8, 2024
bbe0ec7
Fix Clang format failling
chenminghua8 Dec 8, 2024
aaa6acc
Fix Clang format failling
chenminghua8 Dec 8, 2024
cd04f84
Merge branch 'StarRocks:main' into support_dataSketches
chenminghua8 Dec 30, 2024
026988f
Refactor to support DataSketches Quantile、Theta、Frequency Sketches
chenminghua8 Dec 31, 2024
6495748
Refactor to support DataSketches Quantile、Theta、Frequency Sketches
chenminghua8 Dec 31, 2024
78a11af
Refactor to support DataSketches Quantile、Theta、Frequency Sketches
chenminghua8 Dec 31, 2024
40589e6
Merge branch 'StarRocks:main' into support_dataSketches
chenminghua8 Dec 31, 2024
f95f6d4
Merge branch 'support_dataSketches' of github.com:chenminghua8/starro…
chenminghua8 Dec 31, 2024
df3b57b
Refactor to support DataSketches Quantile、Theta、Frequency Sketches
chenminghua8 Dec 31, 2024
35b7ef4
Refactor to support DataSketches Quantile、Theta、Frequency Sketches
chenminghua8 Dec 31, 2024
8cc2d01
Refactor to support DataSketches Quantile、Theta、Frequency Sketches
chenminghua8 Dec 31, 2024
ecac63f
support DataSketches quantile sketche
chenminghua8 Dec 31, 2024
8b1b598
support DataSketches quantile sketche
chenminghua8 Jan 2, 2025
8d08860
Merge branch 'StarRocks:main' into support_quantile_sketche
chenminghua8 Jan 6, 2025
5adb7aa
support DataSketches quantile sketche
chenminghua8 Jan 6, 2025
d3f49cf
Merge branch 'StarRocks:main' into support_quantile_sketche
chenminghua8 Jan 7, 2025
983ea74
support DataSketches quantile sketche
chenminghua8 Jan 7, 2025
ed11a11
support DataSketches quantile sketche
chenminghua8 Jan 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor to support DataSketches Quantile、Theta、Frequency Sketches
Signed-off-by: chenminghua8 <cmptmn@126.com>
  • Loading branch information
chenminghua8 committed Dec 31, 2024
commit 35b7ef4f601663990a1ba6d972b2fc495b665bf2
92 changes: 0 additions & 92 deletions fe/fe-core/src/main/java/com/starrocks/catalog/FunctionSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -1624,98 +1624,6 @@ private void registerBuiltinDsFunction() {
addBuiltin(AggregateFunction.createBuiltin(DS_HLL_COUNT_DISTINCT,
Lists.newArrayList(t, Type.INT, Type.VARCHAR), Type.BIGINT, Type.VARBINARY,
true, false, true));
// ds_theta(col)
addBuiltin(AggregateFunction.createBuiltin(DS_THETA,
Lists.newArrayList(t), Type.BIGINT, Type.VARBINARY,
true, false, true));
}

addBuiltin(AggregateFunction.createBuiltin(DS_QUANTILE,
Lists.newArrayList(Type.DOUBLE), Type.ARRAY_DOUBLE, Type.VARBINARY,
false, false, true));
addBuiltin(AggregateFunction.createBuiltin(DS_QUANTILE,
Lists.newArrayList(Type.FLOAT), Type.ARRAY_FLOAT, Type.VARBINARY,
false, false, true));
addBuiltin(AggregateFunction.createBuiltin(DS_QUANTILE,
Lists.newArrayList(Type.INT), Type.ARRAY_INT, Type.VARBINARY,
false, false, true));
addBuiltin(AggregateFunction.createBuiltin(DS_QUANTILE,
Lists.newArrayList(Type.BIGINT), Type.ARRAY_BIGINT, Type.VARBINARY,
false, false, true));

addBuiltin(AggregateFunction.createBuiltin(DS_QUANTILE,
Lists.newArrayList(Type.DOUBLE, Type.DOUBLE), Type.ARRAY_DOUBLE, Type.VARBINARY,
false, false, true));
addBuiltin(AggregateFunction.createBuiltin(DS_QUANTILE,
Lists.newArrayList(Type.FLOAT, Type.DOUBLE), Type.ARRAY_FLOAT, Type.VARBINARY,
false, false, true));
addBuiltin(AggregateFunction.createBuiltin(DS_QUANTILE,
Lists.newArrayList(Type.INT, Type.DOUBLE), Type.ARRAY_INT, Type.VARBINARY,
false, false, true));
addBuiltin(AggregateFunction.createBuiltin(DS_QUANTILE,
Lists.newArrayList(Type.BIGINT, Type.DOUBLE), Type.ARRAY_BIGINT, Type.VARBINARY,
false, false, true));

addBuiltin(AggregateFunction.createBuiltin(DS_QUANTILE,
Lists.newArrayList(Type.DOUBLE, Type.DOUBLE, Type.INT), Type.ARRAY_DOUBLE, Type.VARBINARY,
false, false, true));
addBuiltin(AggregateFunction.createBuiltin(DS_QUANTILE,
Lists.newArrayList(Type.FLOAT, Type.DOUBLE, Type.INT), Type.ARRAY_FLOAT, Type.VARBINARY,
false, false, true));
addBuiltin(AggregateFunction.createBuiltin(DS_QUANTILE,
Lists.newArrayList(Type.INT, Type.DOUBLE, Type.INT), Type.ARRAY_INT, Type.VARBINARY,
false, false, true));
addBuiltin(AggregateFunction.createBuiltin(DS_QUANTILE,
Lists.newArrayList(Type.BIGINT, Type.DOUBLE, Type.INT), Type.ARRAY_BIGINT, Type.VARBINARY,
false, false, true));

addBuiltin(AggregateFunction.createBuiltin(DS_QUANTILE,
Lists.newArrayList(Type.DOUBLE, Type.ARRAY_DOUBLE), Type.ARRAY_DOUBLE, Type.VARBINARY,
false, false, true));
addBuiltin(AggregateFunction.createBuiltin(DS_QUANTILE,
Lists.newArrayList(Type.FLOAT, Type.ARRAY_DOUBLE), Type.ARRAY_FLOAT, Type.VARBINARY,
false, false, true));
addBuiltin(AggregateFunction.createBuiltin(DS_QUANTILE,
Lists.newArrayList(Type.INT, Type.ARRAY_DOUBLE), Type.ARRAY_INT, Type.VARBINARY,
false, false, true));
addBuiltin(AggregateFunction.createBuiltin(DS_QUANTILE,
Lists.newArrayList(Type.BIGINT, Type.ARRAY_DOUBLE), Type.ARRAY_BIGINT, Type.VARBINARY,
false, false, true));

addBuiltin(AggregateFunction.createBuiltin(DS_QUANTILE,
Lists.newArrayList(Type.DOUBLE, Type.ARRAY_DOUBLE, Type.INT), Type.ARRAY_DOUBLE, Type.VARBINARY,
false, false, true));
addBuiltin(AggregateFunction.createBuiltin(DS_QUANTILE,
Lists.newArrayList(Type.FLOAT, Type.ARRAY_DOUBLE, Type.INT), Type.ARRAY_FLOAT, Type.VARBINARY,
false, false, true));
addBuiltin(AggregateFunction.createBuiltin(DS_QUANTILE,
Lists.newArrayList(Type.INT, Type.ARRAY_DOUBLE, Type.INT), Type.ARRAY_INT, Type.VARBINARY,
false, false, true));
addBuiltin(AggregateFunction.createBuiltin(DS_QUANTILE,
Lists.newArrayList(Type.BIGINT, Type.ARRAY_DOUBLE, Type.INT), Type.ARRAY_BIGINT, Type.VARBINARY,
false, false, true));

ImmutableList<Type> DS_FREQUENT_SUPPORTED_TYPES =
ImmutableList.<Type>builder()
.addAll(Type.FLOAT_TYPES)
.addAll(Type.INTEGER_TYPES)
.addAll(Type.STRING_TYPES)
.addAll(Type.DATE_TYPES)
.build();
for (Type type : DS_FREQUENT_SUPPORTED_TYPES) {
ArrayType retType = DS_FREQUENT_RET_TYPE_BUILDER.apply(type);
addBuiltin(AggregateFunction.createBuiltin(DS_FREQUENT,
Lists.newArrayList(type), retType, Type.VARBINARY,
false, true, true));
addBuiltin(AggregateFunction.createBuiltin(DS_FREQUENT,
Lists.newArrayList(type, Type.BIGINT), retType, Type.VARBINARY,
false, true, true));
addBuiltin(AggregateFunction.createBuiltin(DS_FREQUENT,
Lists.newArrayList(type, Type.BIGINT, Type.INT), retType, Type.VARBINARY,
false, true, true));
addBuiltin(AggregateFunction.createBuiltin(DS_FREQUENT,
Lists.newArrayList(type, Type.BIGINT, Type.INT, Type.INT), retType, Type.VARBINARY,
false, true, true));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,7 @@ private static void analyzeBuiltinAggFunction(FunctionName fnName,
|| fnName.getFunction().equals(FunctionSet.MAX)
|| fnName.getFunction().equals(FunctionSet.NDV)
|| fnName.getFunction().equals(FunctionSet.APPROX_COUNT_DISTINCT)
|| fnName.getFunction().equals(FunctionSet.DS_HLL_COUNT_DISTINCT)
|| fnName.getFunction().equals(FunctionSet.DS_QUANTILE)
|| fnName.getFunction().equals(FunctionSet.DS_FREQUENT)
|| fnName.getFunction().equals(FunctionSet.DS_THETA))
|| fnName.getFunction().equals(FunctionSet.DS_HLL_COUNT_DISTINCT))
&& !arg.getType().canApplyToNumeric()) {
throw new SemanticException(Type.NOT_SUPPORT_AGG_ERROR_MSG);
}
Expand Down Expand Up @@ -547,94 +544,7 @@ private static void analyzeBuiltinAggFunction(FunctionName fnName,
}
}
}

// ds_quantile
if (fnName.getFunction().equals(FunctionSet.DS_QUANTILE)) {
int argSize = functionCallExpr.getChildren().size();
if (argSize > 3 || argSize < 1) {
throw new SemanticException(fnName + " requires one/two/three parameters: ds_quantile(col, ranks, k)");
}
if (!functionCallExpr.getChild(0).getType().isNumericType()) {
throw new SemanticException(
"ds_quantile requires the first parameter's type is numeric type");
}
if (argSize >= 2) {
if (functionCallExpr.getChild(1) instanceof ArrayExpr) {
ArrayExpr ranksArrExpr = (ArrayExpr) functionCallExpr.getChild(1);
int ranksSize = ranksArrExpr.getChildren().size();
for (int i = 0; i < ranksSize; i++) {
if (!(ranksArrExpr.getChild(i) instanceof DecimalLiteral)) {
throw new SemanticException(fnName + " 's second parameter's data type is wrong.");
}
double rank = ((LiteralExpr) ranksArrExpr.getChild(i)).getDoubleValue();
if (rank < 0 || rank > 1) {
throw new SemanticException(
fnName + " rank should be between 0 and 1.");
}
}
} else if ((functionCallExpr.getChild(1) instanceof DecimalLiteral)) {
double rank = ((LiteralExpr) functionCallExpr.getChild(1)).getDoubleValue();
if (rank < 0 || rank > 1) {
throw new SemanticException(
fnName + " rank should be between 0 and 1.");
}
} else {
throw new SemanticException(fnName + " 's second parameter's data type is wrong.");
}
}
if (argSize == 3) {
if (!(functionCallExpr.getChild(2) instanceof IntLiteral)) {
throw new SemanticException(fnName + " 's third parameter's data type is wrong.");
}
long k = ((LiteralExpr) functionCallExpr.getChild(2)).getLongValue();
if (k < 2 || k > 32768) {
throw new SemanticException(
fnName + " third parameter'value should be between 2 and 32768.");
}
}
}

// ds_frequent
if (fnName.getFunction().equals(FunctionSet.DS_FREQUENT)) {
int argSize = functionCallExpr.getChildren().size();
if (argSize > 4) {
throw new SemanticException(fnName + " requires one/two/three/four parameters: ds_frequent(" +
"col, counter_num, lg_max_map_size, lg_start_map_size)");
}
if (argSize >= 2) {
if (!(functionCallExpr.getChild(1) instanceof IntLiteral)) {
throw new SemanticException(fnName + " 's second parameter's data type is wrong.");
}
long counterNum = ((LiteralExpr) functionCallExpr.getChild(1)).getLongValue();
if (counterNum < 1) {
throw new SemanticException(
fnName + " second parameter'value must be greater than 1.");
}
}

if (argSize >= 3) {
if (!(functionCallExpr.getChild(2) instanceof IntLiteral)) {
throw new SemanticException(fnName + " 's third parameter's data type is wrong.");
}
long lgMaxMapSize = ((LiteralExpr) functionCallExpr.getChild(2)).getLongValue();
if (lgMaxMapSize < 3 || lgMaxMapSize > 21) {
throw new SemanticException(
fnName + " third parameter'value should be between 3 and 21.");
}
}

if (argSize == 4) {
if (!(functionCallExpr.getChild(3) instanceof IntLiteral)) {
throw new SemanticException(fnName + " 's third parameter's data type is wrong.");
}
long lgStartMapSize = ((LiteralExpr) functionCallExpr.getChild(3)).getLongValue();
if (lgStartMapSize < 3 || lgStartMapSize > 21) {
throw new SemanticException(
fnName + " fourth parameter'value should be between 3 and 21.");
}
}
}


if (fnName.getFunction().equals(FunctionSet.COVAR_POP) || fnName.getFunction().equals(FunctionSet.COVAR_SAMP) ||
fnName.getFunction().equals(FunctionSet.CORR)) {
if (functionCallExpr.getChildren().size() != 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,44 +307,4 @@ public void testWindowFunnelFunction() {
analyzeSuccess("SELECT window_funnel(1, ta, 0, [ta='a', ta='b']) FROM tall");
analyzeSuccess("SELECT window_funnel(1, ta, 0, [true, true, false]) FROM tall");
}

@Test
public void testDsHll() {
analyzeSuccess("select ds_hll(v1) from t0");
analyzeSuccess("select ds_hll(v1, 4) from t0");
analyzeSuccess("select ds_hll(v1, 10, 'HLL_6') from t0");
}

@Test
public void testDsTheta() {
analyzeSuccess("select ds_theta(v1) from t0");
}

@Test
public void testDsQuantile() {
analyzeSuccess("select ds_quantile(v1) from t0");
analyzeSuccess("select ds_quantile(v1, 0.5) from t0");
analyzeSuccess("select ds_quantile(v1, 0.5, 21) from t0");
analyzeFail("select ds_quantile(v1, 2) from t0");
analyzeFail("select ds_quantile(v1, '0.5', 21) from t0");
analyzeFail("select ds_quantile(v1, 0.5, 32769) from t0");
analyzeFail("select ds_quantile(v1, ['0.5', '0.6'], 21) from t0");
analyzeFail("select ds_quantile(v1, [2.0, 3.0], 21) from t0");
analyzeFail("select ds_quantile(v1, 0.5, 21, 21) from t0");
analyzeFail("select ds_quantile(v1, 0.5, '21') from t0");
}
@Test
public void testDsFrequent() {
analyzeSuccess("select ds_frequent(v1) from t0");
analyzeSuccess("select ds_frequent(v1, 10) from t0");
analyzeSuccess("select ds_frequent(v1, 10, 20) from t0");
analyzeSuccess("select ds_frequent(v1, 10, 20, 16) from t0");
analyzeFail("select ds_frequent(v1, '10') from t0");
analyzeFail("select ds_frequent(v1, 0) from t0");
analyzeFail("select ds_frequent(v1, 10, '20') from t0");
analyzeFail("select ds_frequent(v1, 10, 200) from t0");
analyzeFail("select ds_frequent(v1, 10, 20, '16') from t0");
analyzeFail("select ds_frequent(v1, 10, 20, 200) from t0");
analyzeFail("select ds_frequent(v1, 10, 20, 16, 16) from t0");
}
}
Loading