-
Notifications
You must be signed in to change notification settings - Fork 10
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
f834908
commit 0a9241b
Showing
6 changed files
with
190 additions
and
8 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
13 changes: 13 additions & 0 deletions
13
hibernate-dialect/src/main/java/tech/ydb/hibernate/dialect/hint/QueryHintHandler.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,13 @@ | ||
package tech.ydb.hibernate.dialect.hint; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author Kirill Kurdyukov | ||
*/ | ||
public interface QueryHintHandler { | ||
|
||
String addQueryHints(String query, List<String> hints); | ||
|
||
boolean commentIsHint(String comment); | ||
} |
42 changes: 42 additions & 0 deletions
42
hibernate-dialect/src/main/java/tech/ydb/hibernate/dialect/hint/ScanQueryHintHandler.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,42 @@ | ||
package tech.ydb.hibernate.dialect.hint; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Kirill Kurdyukov | ||
*/ | ||
public class ScanQueryHintHandler implements QueryHintHandler { | ||
public static final ScanQueryHintHandler INSTANCE = new ScanQueryHintHandler(); | ||
|
||
private static final String HINT_USE_SCAN = "use_scan"; | ||
|
||
private ScanQueryHintHandler() { | ||
|
||
} | ||
|
||
@Override | ||
public String addQueryHints(String query, List<String> hints) { | ||
if (hints.isEmpty()) { | ||
return query; | ||
} | ||
|
||
var useScan = new ArrayList<String>(); | ||
hints.forEach(hint -> { | ||
if (hint.startsWith(HINT_USE_SCAN)) { | ||
useScan.add(hint.substring(HINT_USE_SCAN.length())); | ||
} | ||
}); | ||
|
||
if (useScan.size() == 1) { | ||
return "scan " + query; | ||
} | ||
|
||
return query; | ||
} | ||
|
||
@Override | ||
public boolean commentIsHint(String comment) { | ||
return comment.startsWith(HINT_USE_SCAN); | ||
} | ||
} |
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