forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[enhancement](Nereids) boost characterLiteralTypeCoercion (apache#42941)
Boost characterLiteralTypeCoercion by check the string format and skip throw Throwable when can not parse string to integer/float/date/datetime. This logical usually appear when search `If` function signature, because the If has lots of signature, we need cast argument to the signature type to matches the best signature, for example: ``` select if(column_1, 'xxx', 'yyy') ``` we will check whether the 'xxx' and 'yyy' can be parsed to int/datetime and so on. In some scenarios, this optimize can provide 16% QPS before: optimize: <img width="1901" alt="image" src="https://github.com/user-attachments/assets/b03d2d29-5d3b-45a6-ba54-2bcc7c2dccca"> <img width="1484" alt="image" src="https://github.com/user-attachments/assets/82cbb2b0-dfe8-4a05-bc2f-ebb35dc23209"> after optimize: <img width="1724" alt="image" src="https://github.com/user-attachments/assets/d60a867d-596d-4ac1-9377-6460ed6d3dd1"> <img width="1722" alt="image" src="https://github.com/user-attachments/assets/c9c9f72c-3a5f-4c24-95d9-9ca99ecab0a6">
- Loading branch information
Showing
28 changed files
with
1,604 additions
and
319 deletions.
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
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
66 changes: 66 additions & 0 deletions
66
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/Result.java
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,66 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.apache.doris.nereids.trees.expressions.literal; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Supplier; | ||
|
||
/** Result */ | ||
public class Result<R, T extends RuntimeException> { | ||
private final Optional<R> result; | ||
private final Optional<Supplier<T>> exceptionSupplier; | ||
|
||
private Result(Optional<R> result, Optional<Supplier<T>> exceptionSupplier) { | ||
this.result = result; | ||
this.exceptionSupplier = exceptionSupplier; | ||
} | ||
|
||
public static <R, T extends RuntimeException> Result<R, T> ok(R result) { | ||
return new Result<>(Optional.of(result), Optional.empty()); | ||
} | ||
|
||
public static <R, T extends RuntimeException> Result<R, T> err(Supplier<T> exceptionSupplier) { | ||
return new Result<>(Optional.empty(), Optional.of(exceptionSupplier)); | ||
} | ||
|
||
public boolean isOk() { | ||
return !exceptionSupplier.isPresent(); | ||
} | ||
|
||
public boolean isError() { | ||
return exceptionSupplier.isPresent(); | ||
} | ||
|
||
public <R, T extends RuntimeException> Result<R, T> cast() { | ||
return (Result<R, T>) this; | ||
} | ||
|
||
public R get() { | ||
if (exceptionSupplier.isPresent()) { | ||
throw exceptionSupplier.get().get(); | ||
} | ||
return result.get(); | ||
} | ||
|
||
public R orElse(R other) { | ||
if (exceptionSupplier.isPresent()) { | ||
return other; | ||
} | ||
return result.get(); | ||
} | ||
} |
Oops, something went wrong.