@@ -68,8 +68,8 @@ namespace NSQLComplete {
6868
6969 return MakeUnionNameService (std::move (children), MakeDummyRanking ())
7070 ->Lookup (std::move (request))
71- .Apply ([this , input, context = std::move (context)](auto f) {
72- return ToCompletion (input, context, f.ExtractValue ());
71+ .Apply ([this , input, context = std::move (context), global = std::move (global) ](auto f) {
72+ return ToCompletion (input, std::move ( context), global , f.ExtractValue ());
7373 });
7474 }
7575
@@ -148,7 +148,7 @@ namespace NSQLComplete {
148148
149149 if (context.Column && global.Column ) {
150150 request.Constraints .Column = TColumnName::TConstraints ();
151- request.Constraints .Column ->Tables = std::move ( global.Column ->Tables );
151+ request.Constraints .Column ->Tables = global.Column ->TablesWithAlias (context. Column -> Table );
152152 }
153153
154154 return request;
@@ -157,10 +157,11 @@ namespace NSQLComplete {
157157 TCompletion ToCompletion (
158158 TCompletionInput input,
159159 TLocalSyntaxContext context,
160+ const TGlobalContext& global,
160161 TNameResponse response) const {
161162 TCompletion completion = {
162163 .CompletedToken = GetCompletedToken (input, context.EditRange ),
163- .Candidates = Convert (std::move (response.RankedNames ), std::move (context)),
164+ .Candidates = Convert (std::move (response.RankedNames ), std::move (context), global ),
164165 };
165166
166167 if (response.NameHintLength ) {
@@ -175,16 +176,33 @@ namespace NSQLComplete {
175176 return completion;
176177 }
177178
178- static TVector<TCandidate> Convert (TVector<TGenericName> names, TLocalSyntaxContext context) {
179+ static TVector<TCandidate> Convert (
180+ TVector<TGenericName> names,
181+ TLocalSyntaxContext context,
182+ const TGlobalContext& global) {
179183 TVector<TCandidate> candidates;
180184 candidates.reserve (names.size ());
181185 for (auto & name : names) {
182- candidates.emplace_back (Convert (std::move (name), context));
186+ candidates.emplace_back (Convert (std::move (name), context, global ));
183187 }
184188 return candidates;
185189 }
186190
187- static TCandidate Convert (TGenericName name, TLocalSyntaxContext& context) {
191+ // TODO(YQL-19747): extract to a separate file
192+ static TCandidate Convert (
193+ TGenericName name,
194+ TLocalSyntaxContext& context,
195+ const TGlobalContext& global) {
196+ // TODO(YQL-19747): support multiple aliases for a single table
197+ THashMap<TTableId, TString> aliasByTable;
198+ global.Column .Transform ([&](auto && column) {
199+ aliasByTable.reserve (column.Tables .size ());
200+ for (const auto & table : column.Tables ) {
201+ aliasByTable[table] = table.Alias ;
202+ }
203+ return std::monostate ();
204+ });
205+
188206 return std::visit ([&](auto && name) -> TCandidate {
189207 using T = std::decay_t <decltype (name)>;
190208
@@ -241,6 +259,12 @@ namespace NSQLComplete {
241259 }
242260
243261 if constexpr (std::is_base_of_v<TColumnName, T>) {
262+ const TString& alias = aliasByTable.at (name.Table );
263+ if (context.Column ->Table .empty () && !alias.empty ()) {
264+ name.Indentifier .prepend (' .' );
265+ name.Indentifier .prepend (alias);
266+ }
267+
244268 return {ECandidateKind::ColumnName, std::move (name.Indentifier )};
245269 }
246270
0 commit comments