Skip to main content

session/
hints.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// For the given format: `x-greptime-hints: auto_create_table=true, ttl=7d`
16pub const HINTS_KEY: &str = "x-greptime-hints";
17/// Deprecated, use `HINTS_KEY` instead. Notes if "x-greptime-hints" is set, keys with this prefix will be ignored.
18pub const HINTS_KEY_PREFIX: &str = "x-greptime-hint-";
19pub const REMOTE_QUERY_ID_EXTENSION_KEY: &str = "remote_query_id";
20pub const INITIAL_REMOTE_DYN_FILTER_REGISTRATIONS_EXTENSION_KEY: &str =
21    "initial_remote_dyn_filter_registrations";
22pub const SUPPORT_FLIGHT_METRICS_BEFORE_BATCH_EXTENSION_KEY: &str =
23    "query.support_flight_metrics_before_batch";
24pub const LIVE_ANALYZE_METRICS_EXTENSION_KEY: &str = "query.live_analyze_metrics";
25
26/// Skip WAL for this insert only; never persisted as a table option.
27pub const INSERT_SKIP_WAL_HINT: &str = "insert_skip_wal";
28
29pub const READ_PREFERENCE_HINT: &str = "read_preference";
30pub const RESERVED_EXTENSION_KEYS: [&str; 4] = [
31    REMOTE_QUERY_ID_EXTENSION_KEY,
32    INITIAL_REMOTE_DYN_FILTER_REGISTRATIONS_EXTENSION_KEY,
33    SUPPORT_FLIGHT_METRICS_BEFORE_BATCH_EXTENSION_KEY,
34    LIVE_ANALYZE_METRICS_EXTENSION_KEY,
35];
36
37/// Deprecated, use `HINTS_KEY` instead.
38pub const HINT_KEYS: [&str; 7] = [
39    "x-greptime-hint-auto_create_table",
40    "x-greptime-hint-ttl",
41    "x-greptime-hint-append_mode",
42    "x-greptime-hint-merge_mode",
43    "x-greptime-hint-physical_table",
44    "x-greptime-hint-skip_wal",
45    "x-greptime-hint-read_preference",
46];
47
48pub fn is_reserved_extension_key(key: &str) -> bool {
49    RESERVED_EXTENSION_KEYS.contains(&key)
50}
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_is_reserved_extension_key() {
58        assert!(is_reserved_extension_key(REMOTE_QUERY_ID_EXTENSION_KEY));
59        assert!(is_reserved_extension_key(
60            INITIAL_REMOTE_DYN_FILTER_REGISTRATIONS_EXTENSION_KEY
61        ));
62        assert!(is_reserved_extension_key(
63            SUPPORT_FLIGHT_METRICS_BEFORE_BATCH_EXTENSION_KEY
64        ));
65        assert!(is_reserved_extension_key(
66            LIVE_ANALYZE_METRICS_EXTENSION_KEY
67        ));
68        assert!(!is_reserved_extension_key(READ_PREFERENCE_HINT));
69    }
70}