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