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
26pub const READ_PREFERENCE_HINT: &str = "read_preference";
27pub const RESERVED_EXTENSION_KEYS: [&str; 4] = [
28    REMOTE_QUERY_ID_EXTENSION_KEY,
29    INITIAL_REMOTE_DYN_FILTER_REGISTRATIONS_EXTENSION_KEY,
30    SUPPORT_FLIGHT_METRICS_BEFORE_BATCH_EXTENSION_KEY,
31    LIVE_ANALYZE_METRICS_EXTENSION_KEY,
32];
33
34/// Deprecated, use `HINTS_KEY` instead.
35pub const HINT_KEYS: [&str; 7] = [
36    "x-greptime-hint-auto_create_table",
37    "x-greptime-hint-ttl",
38    "x-greptime-hint-append_mode",
39    "x-greptime-hint-merge_mode",
40    "x-greptime-hint-physical_table",
41    "x-greptime-hint-skip_wal",
42    "x-greptime-hint-read_preference",
43];
44
45pub fn is_reserved_extension_key(key: &str) -> bool {
46    RESERVED_EXTENSION_KEYS.contains(&key)
47}
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn test_is_reserved_extension_key() {
55        assert!(is_reserved_extension_key(REMOTE_QUERY_ID_EXTENSION_KEY));
56        assert!(is_reserved_extension_key(
57            INITIAL_REMOTE_DYN_FILTER_REGISTRATIONS_EXTENSION_KEY
58        ));
59        assert!(is_reserved_extension_key(
60            SUPPORT_FLIGHT_METRICS_BEFORE_BATCH_EXTENSION_KEY
61        ));
62        assert!(is_reserved_extension_key(
63            LIVE_ANALYZE_METRICS_EXTENSION_KEY
64        ));
65        assert!(!is_reserved_extension_key(READ_PREFERENCE_HINT));
66    }
67}