OmniSciDB  cde582ebc3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TokenCompletionHints.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef THRIFTHANDLER_TOKENCOMPLETIONHINTS_H
18 #define THRIFTHANDLER_TOKENCOMPLETIONHINTS_H
19 
20 #include "gen-cpp/completion_hints_types.h"
21 // completion_hints_types.h > Thrift.h > PlatformSocket.h > winsock2.h > windows.h
23 
24 #include <unordered_map>
25 #include <unordered_set>
26 
27 // Find last "word" (can contain: alphanumeric, underscore, dot) from position
28 // `cursor` inside or at the end of `sql`.
29 std::string find_last_word_from_cursor(const std::string& sql, const int64_t cursor);
30 
31 // Only allows a few whitelisted keywords, filters out everything else.
32 std::vector<TCompletionHint> just_whitelisted_keyword_hints(
33  const std::vector<TCompletionHint>& hints);
34 
35 // Given last_word = "table.prefix", returns column hints for all columns in "table" which
36 // start with "prefix" from `column_names_by_table["table"]`. Returns true iff `last_word`
37 // looks like a qualified name (contains a dot).
39  std::vector<TCompletionHint>& hints,
40  const std::string& last_word,
41  const std::unordered_map<std::string, std::unordered_set<std::string>>&
42  column_names_by_table);
43 
44 // Returns column hints for the flattened list of all values in `column_names_by_table`
45 // which start with `last_word`.
46 void get_column_hints(
47  std::vector<TCompletionHint>& hints,
48  const std::string& last_word,
49  const std::unordered_map<std::string, std::unordered_set<std::string>>&
50  column_names_by_table);
51 
52 // Returns true iff it should suggest columns or just the FROM keyword,
53 // should be called for partial queries after SELECT but before FROM.
54 bool should_suggest_column_hints(const std::string& partial_query);
55 
56 #endif // THRIFTHANDLER_TOKENCOMPLETIONHINTS_H
std::vector< TCompletionHint > just_whitelisted_keyword_hints(const std::vector< TCompletionHint > &hints)
void get_column_hints(std::vector< TCompletionHint > &hints, const std::string &last_word, const std::unordered_map< std::string, std::unordered_set< std::string >> &column_names_by_table)
bool get_qualified_column_hints(std::vector< TCompletionHint > &hints, const std::string &last_word, const std::unordered_map< std::string, std::unordered_set< std::string >> &column_names_by_table)
std::string find_last_word_from_cursor(const std::string &sql, const int64_t cursor)
bool should_suggest_column_hints(const std::string &partial_query)