OmniSciDB  5ade3759e0
TokenCompletionHints.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, 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 
22 #include <unordered_map>
23 #include <unordered_set>
24 
25 // Find last "word" (can contain: alphanumeric, underscore, dot) from position
26 // `cursor` inside or at the end of `sql`.
27 std::string find_last_word_from_cursor(const std::string& sql, const ssize_t cursor);
28 
29 // Only allows a few whitelisted keywords, filters out everything else.
30 std::vector<TCompletionHint> just_whitelisted_keyword_hints(
31  const std::vector<TCompletionHint>& hints);
32 
33 // Given last_word = "table.prefix", returns column hints for all columns in "table" which
34 // start with "prefix" from `column_names_by_table["table"]`. Returns true iff `last_word`
35 // looks like a qualified name (contains a dot).
37  std::vector<TCompletionHint>& hints,
38  const std::string& last_word,
39  const std::unordered_map<std::string, std::unordered_set<std::string>>&
40  column_names_by_table);
41 
42 // Returns column hints for the flattened list of all values in `column_names_by_table`
43 // which start with `last_word`.
44 void get_column_hints(
45  std::vector<TCompletionHint>& hints,
46  const std::string& last_word,
47  const std::unordered_map<std::string, std::unordered_set<std::string>>&
48  column_names_by_table);
49 
50 // Returns true iff it should suggest columns or just the FROM keyword,
51 // should be called for partial queries after SELECT but before FROM.
52 bool should_suggest_column_hints(const std::string& partial_query);
53 
54 #endif // THRIFTHANDLER_TOKENCOMPLETIONHINTS_H
auto sql(const std::string &sql_stmts)
std::vector< TCompletionHint > just_whitelisted_keyword_hints(const std::vector< TCompletionHint > &hints)
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)
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 should_suggest_column_hints(const std::string &partial_query)
std::string find_last_word_from_cursor(const std::string &sql, const ssize_t cursor)