Query statement completion method and device, equipment and storage medium

By predicting lexical types in SQL statements and retrieving candidate words from database metadata, the inaccurate SQL statement completion problem in existing technologies is solved, enabling personalized intelligent completion that is applicable to various SQL editing tools and improves development efficiency.

CN122363674APending Publication Date: 2026-07-10TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-03-10
Publication Date
2026-07-10

AI Technical Summary

Technical Problem

Existing SQL statement completion methods cannot provide effective suggestions related to the current database environment, resulting in low completion accuracy and failing to meet the personalized needs of different user groups.

Method used

By obtaining query statement and cursor position information, the type of target word is predicted, and candidate words are recalled from database metadata to generate a candidate list to complete the target word.

Benefits of technology

It improves the accuracy and relevance of SQL statement completion, can recognize user intent, provide personalized recommendations, is compatible with various SQL editing tools, and enhances development efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122363674A_ABST
    Figure CN122363674A_ABST
Patent Text Reader

Abstract

The application provides a query statement completion method and device, equipment and a storage medium, which can be applied to code completion and the like. The method comprises the following steps: obtaining a first query statement being edited by an object and position information of an input cursor in the first query statement, the first query statement being used for querying data from a database; predicting a first word element type of a target word element appearing after the input cursor based on the first query statement and the position information of the input cursor; if the first word element type is a first metadata type, recalling a first metadata candidate word of the target word element from database metadata based on the first metadata type, wherein the first metadata type is any one of M metadata types; and generating a candidate list of the target word element based on the first metadata candidate word, the candidate list being used for completing the target word element. In this way, the relevance and accuracy of the completion result are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a query statement completion method, apparatus, device, and storage medium. Background Technology

[0002] With the advent of the big data era, Structured Query Language (SQL), as a core tool for data analysis and database management, is widely used in various business scenarios. Developers and data analysts frequently need to write SQL queries in their daily work to extract, filter, and analyze data from databases. Therefore, improving the efficiency of SQL statement writing has become one of the key aspects of optimizing the data development process.

[0003] Current integrated development environments (IDEs) and database client tools generally offer code completion functionality to help users quickly input SQL statements. However, current SQL statement completion methods are completely detached from the user's current database environment and cannot provide any effective database-related suggestions, resulting in low accuracy and poor completion effects. Summary of the Invention

[0004] This application provides a query statement completion method, apparatus, device, and storage medium, which can improve the accuracy and effect of query statement completion.

[0005] Firstly, this application provides a query statement completion method, including: Obtain the first query statement that the object is currently editing, as well as the position information of the input cursor in the first query statement, which is used to query data from the database; Based on the first query statement and the position information of the input cursor, predict the first word type of the target word that appears after the input cursor. The first word type belongs to one of N word types. The N word types include M metadata types, where N is a positive integer greater than 1 and M is a positive integer greater than 1 and less than N. If the first lexical type is the first metadata type, then based on the first metadata type, the first metadata candidate word of the target lexical is recalled from the database metadata, where the first metadata type is any one of the M metadata types; Based on the first metadata candidate words, a candidate list of the target word is generated, and the candidate list is used to complete the target word.

[0006] Secondly, this application provides a query completion device, comprising: The acquisition unit is used to acquire the first query statement that the object is editing, and the position information of the input cursor in the first query statement, which is used to query data from the database; The type prediction unit is used to predict the first word type of the target word that appears after the input cursor based on the first query statement and the position information of the input cursor. The first word type belongs to one of N word types. The N word types include M metadata types, where N is a positive integer greater than 1 and M is a positive integer greater than 1 and less than N. The recall unit is used to recall the first metadata candidate word of the target word from the database metadata based on the first metadata type when the first word type is the first metadata type. The first metadata type is any one of the M metadata types. The generation unit is configured to generate a candidate list of the target lexical based on the first metadata candidate words, the candidate list being used to complete the target lexical.

[0007] In some embodiments, the type prediction unit is specifically used to: extract the current query segment where the input cursor is located from the first query statement based on the position information of the input cursor; insert a preset placeholder after the input cursor; perform syntactic parsing on the current query segment with the inserted preset placeholder to predict the word type to which the preset placeholder belongs; and determine the first word type of the target word based on the word type to which the preset placeholder belongs.

[0008] In some embodiments, the recall unit is specifically configured to recall the first metadata candidate word of the target term from the database metadata based on the first metadata type and the first query statement.

[0009] In some embodiments, if the first metadata type is a database name, then the first metadata candidate terms include candidate database names. The recall unit is specifically configured to: if, based on the first query statement, it is detected that the object has not entered a database name prefix, then recall each database name included in the database metadata; if, based on the first query statement, it is detected that the object has entered a database name prefix, then, based on the database name prefix, recall database names whose prefix is ​​the database name prefix from each database name included in the database metadata; obtain each database name used by the object in a historical time period, and the popularity value of each used database name; and determine the candidate database name based on the recalled database names, the used database names, and the popularity value of each used database name.

[0010] In some embodiments, if the first metadata type is a table name, then the first metadata candidate terms include candidate table names. The recall unit is specifically configured to: when, based on the first query statement, it is detected that the object inputs a database name but does not input a table name prefix, recall each table name under the database name input by the object from the database metadata; when, based on the first query statement, it is detected that the object inputs both a database name and a table name prefix, recall each table under the database name input by the object from the database metadata whose prefix is ​​the table name prefix; obtain each table name used by the object in a historical time period, and the popularity value of each used table name; and determine the candidate table name based on the recalled table names, the used table names, and the popularity value of each used table name.

[0011] In some embodiments, if the first metadata type is a field, then the first metadata candidate terms include candidate fields. The recall unit is specifically configured to: when, based on the first query statement, it is detected that the object has entered a table name but has not entered a field prefix, recall each field under the table name entered by the object from the database metadata; when, based on the first query statement, it is detected that the object has entered a table name and a field prefix, recall fields with the field prefix from each field under the table name entered by the object in the database metadata; obtain each field used by the object in a historical time period, and the popularity value of each used field; and determine the candidate fields based on the recalled fields, the used fields, and the popularity values ​​of each used field.

[0012] In some embodiments, if the first metadata type is an enumeration value, then the first metadata candidate terms include candidate enumeration values. The recall unit is specifically configured to, based on the first query statement, detect that the object has an input field, and the input field is an enumeration type, recall a list of enumeration values ​​of the input field from the database metadata based on the table name and database name to which the input field belongs; obtain each enumeration value used by the object in a historical time period, and the popularity value of each used enumeration value; and determine the candidate enumeration value based on the recalled enumeration value list, each used enumeration value, and the popularity value of each used enumeration value.

[0013] In some embodiments, the generation unit is specifically configured to segment the first query statement into words, and based on the position information of the input cursor, mask the word units in the segmented first query statement to obtain a masked first query statement; through a trained word order prediction model, perform prediction processing on the masked first query statement to obtain the probability value of the target word unit belonging to each of the N word unit types, and the word unit prediction value of the target word unit under each word unit type; and generate a candidate list of the target word unit based on the first metadata candidate words of the target word unit, the probability value of the target word unit belonging to each word unit type, and the word unit prediction value of the target word unit under each word unit type.

[0014] In some embodiments, the generation unit is specifically used to generalize the metadata type tokens in the first query statement after the mask to the corresponding unified tokens to obtain a first token sequence; determine the token type corresponding to each token in the first token sequence except the mask to obtain a first token type sequence; and process the first token sequence and the first token type sequence through the trained word order prediction model to obtain the probability value of the target token belonging to each token type and the token prediction value of the target token under each token type.

[0015] In some embodiments, the trained word order prediction model includes an embedding module and a prediction model. The generation unit is specifically used to extract the embedding information of the first word sequence and the embedding information of the first word type sequence through the embedding module; fuse the embedding information of the first word sequence and the embedding information of the first word type sequence to obtain fused embedding information; and perform prediction processing on the fused embedding information through the prediction module to obtain the probability value of the target word belonging to each word type and the word prediction value of the target word under each word type.

[0016] In some embodiments, the generation unit is specifically configured to: read from the probability values ​​of the target lexical belonging to each lexical type the probability value of the target lexical belonging to the first metadata type, and the probability value of the target lexical belonging to each of the NM non-metadata types, wherein the NM non-metadata types are lexical types other than the M metadata types among the N lexical types; determine the probability value of each first metadata candidate word of the target lexical based on the probability value of the target lexical belonging to the first metadata type; for each of the NM non-metadata types, determine the probability value of the word prediction value of the target lexical under the non-metadata type based on the probability value of the target lexical belonging to the non-metadata type; and sort the first metadata candidate words and the word prediction value of the target lexical under each non-metadata type based on the probability values ​​of each first metadata candidate word and the probability value of the word prediction value of the target lexical under each non-metadata type to generate a candidate list of the target lexical.

[0017] In some embodiments, the generating unit is further configured to: read the maximum probability value among the probability values ​​of the target word belonging to the M metadata types from the probability values ​​of the target word belonging to the N word types; if the second metadata type corresponding to the maximum probability value is different from the first metadata type, then, based on the second metadata type, recall the second metadata candidate word of the target word from the database metadata; determine the probability value of each second metadata candidate word of the target word based on the probability value of the target word belonging to the second metadata type; and sort each first metadata candidate word, each second metadata candidate word, and the word prediction value of the target word in each non-metadata type based on the probability values ​​of each first metadata candidate word, the probability values ​​of each second metadata candidate word, and the probability value of the word prediction value of the target word in each non-metadata type to generate a candidate list of the target word.

[0018] In some embodiments, the generating unit is specifically configured to sort each first metadata candidate word, each second metadata candidate word, and the lexical prediction value of the target lexical word in each non-metadata type based on the probability value of each first metadata candidate word, the probability value of each second metadata candidate word, and the probability value of the lexical prediction value of the target lexical word in each non-metadata type, to obtain a first candidate sort; determine the popularity value of each first metadata candidate word and the hot spot value of each second metadata candidate word; internally arrange each first metadata candidate word in the first candidate sort based on the popularity value of each first metadata candidate word, and internally arrange each second metadata candidate word in the first candidate sort based on the popularity value of each second metadata candidate word, to obtain the candidate list.

[0019] In some embodiments, the generating unit is specifically configured to set the popularity value of the first metadata candidate word that is consistent with the word prediction value of the target word under the first metadata type as the highest popularity value among the first metadata candidate words; and to set the popularity value of the second metadata candidate word that is consistent with the word prediction value of the target word under the second metadata type as the highest popularity value among the second metadata candidate words.

[0020] In some embodiments, the process of training the word order prediction model includes: acquiring training samples, the training samples including training query statements; performing word segmentation on the training query statements, and masking the word units in the segmented training query statements based on random positions to obtain masked training query statements; performing prediction processing on the masked training query statements using the word order prediction model to obtain the probability value of the word unit at the random position belonging to each word unit type, and the word unit prediction value of the word unit at the random position under each word unit type; determining the model loss value based on the probability value of the word unit at the random position belonging to each word unit type, and the word unit prediction value of the word unit at the random position under each word unit type, and training the word order prediction model based on the model loss value to obtain the trained word order prediction model.

[0021] In some embodiments, the step of performing prediction processing on the masked training query statement using the word order prediction model to obtain the probability value of the word element at the random position belonging to each word element type, and the word element prediction value of the word element at the random position under each word element type, includes: generalizing the word elements belonging to the metadata type in the masked training query statement to the corresponding unified word elements to obtain a second word element sequence; determining the word element type corresponding to each word element in the second word element sequence excluding the mask to obtain a second word element type sequence; and performing prediction processing on the second word element sequence and the second word element type sequence using the word order prediction model to obtain the probability value of the word element at the random position belonging to each word element type, and the word element prediction value of the word element at the random position under each word element type.

[0022] In some embodiments, determining the model loss value based on the probability value of the word at the random position belonging to each word type and the word prediction value of the word at the random position under each word type includes: determining the target word type with the highest probability value from the probability values ​​of the word at the random position belonging to each word type; determining the word type prediction loss value based on the probability value of the word at the random position belonging to the target word type and the true word type of the word at the random position in the training query statement; determining the word prediction loss value based on the word prediction value of the word at the random position under the target word type and the true word at the random position in the training query statement; and determining the model loss value based on the word type prediction loss value and the word prediction loss value.

[0023] Thirdly, this application provides a computing device including a processor and a memory. The memory is used to store a computer program, and the processor is used to invoke and run the computer program stored in the memory to perform the method described in the first aspect.

[0024] Fourthly, a chip is provided for implementing the methods of various implementations of the first aspect described above. Specifically, the chip includes a processor for retrieving and running a computer program from a memory, causing a device equipped with the chip to perform the methods of the first aspect described above.

[0025] Fifthly, a computer-readable storage medium is provided for storing a computer program that causes a computer to perform the method described in the first aspect.

[0026] In a sixth aspect, a computer program product is provided, including computer program instructions that cause a computer to perform the method described in the first aspect.

[0027] In a seventh aspect, a computer program is provided that, when run on a computer, causes the computer to perform the method described in the first aspect.

[0028] In summary, this application proposes a novel query completion method. It obtains the first query statement being edited by the object and the position information of the input cursor within the first query statement, which is used to retrieve data from a database. Next, based on the first query statement and the position information of the input cursor, it predicts the first word type of the target word appearing after the input cursor. This first word type belongs to one of N word types, and these N word types include M metadata types (e.g., database name, table name, field name, etc.). If the first word type is a first metadata type, then based on this first metadata type, it retrieves first metadata candidate words for the target word from the database metadata, where the first metadata type is any one of the M metadata types. Furthermore, based on the first metadata candidate words, a candidate list for the target word is generated, which is used to complete the target word. Therefore, this embodiment of the application, by obtaining the query statement being edited by the object and the position of the input cursor, first predicts the word type (i.e., the first word type) of the target word after the input cursor. When the predicted type (i.e., the first term type) is a metadata type, the corresponding metadata candidate words are retrieved from the database metadata. This mechanism of first predicting the type and then specifically retrieving metadata ensures that the recommendation results not only conform to grammatical norms but also closely match the actual structure of the current database. This avoids the problem of recommendation results being disconnected from database objects in traditional static completion, thereby improving the relevance and accuracy of the completion results. Simultaneously, through term type prediction, this embodiment can identify whether the object currently needs editing a table name, field name, or enumeration value, enhancing the understanding of user intent and thus accurately locating the recall scope. Furthermore, the query statement completion method provided in this embodiment does not depend on specific database products or IDE platforms and can be widely applied to various software tools that support SQL editing, providing a consistent intelligent completion experience for different user groups, demonstrating good versatility and adaptability. Attached Figure Description

[0029] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0030] Figure 1 A schematic diagram illustrating the implementation environment of a query statement completion method provided in this application embodiment; Figure 2A flowchart illustrating a query completion method provided in an embodiment of this application; Figure 3 This is a schematic diagram illustrating a pop-up completion method according to an embodiment of this application; Figure 4 This is a schematic diagram illustrating the interaction between a terminal device and a server. Figure 5 This is a schematic diagram of training a word order prediction model; Figure 6A This is another training diagram for the word order prediction model; Figure 6B This is another training diagram for a word order prediction model; Figure 7 This is a schematic diagram illustrating the use of a trained word order prediction model to predict lexical types and lexical units. Figure 8 Another schematic diagram for using a trained word order prediction model to predict lexical types and lexical units; Figure 9 This is a schematic diagram illustrating other completion strategies involved in the embodiments of this application; Figures 10A to 10C A schematic diagram illustrating several candidate lists generated for embodiments of this application; Figure 11 A flowchart illustrating a query completion method provided in an embodiment of this application; Figure 12 This is a schematic diagram of a two-way completion strategy involved in an embodiment of this application; Figure 13 A flowchart illustrating a query completion method provided in an embodiment of this application; Figure 14 This is a schematic diagram of an overall architecture according to an embodiment of this application; Figure 15 This is a schematic block diagram of a query completion device provided in an embodiment of this application; Figure 16 This is a schematic block diagram of a computing device provided in an embodiment of this application. Detailed Implementation

[0031] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.

[0032] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. In embodiments of the invention, "B corresponding to A" means that B is associated with A. In one implementation, B can be determined based on A. However, it should also be understood that determining B based on A does not mean determining B solely based on A; B can also be determined based on A and / or other information. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or server that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products, or devices. In the description of this application, unless otherwise stated, "a plurality of" means two or more.

[0033] To facilitate understanding of the embodiments of this application, the relevant concepts involved in the embodiments of this application will first be introduced: IDE (Integrated Development Environment) is a software application that integrates multiple tools and functions needed for software development. It typically includes a code editor, compiler, debugger, automated build tools, version control system, etc., providing developers with a centralized development environment that facilitates the development, testing, and debugging of software. Using an IDE can significantly improve development efficiency and reduce the time spent switching between different tools.

[0034] SQL: Structured Query Language, is a standardized, domain-specific programming language used to operate relational database management systems. It is mainly used for querying, updating, defining, and controlling data in the database.

[0035] LSP: Language Server Protocol, is an open protocol designed to provide standard language feature support for various programming languages ​​and tools. This protocol allows communication between a language server and an editor (such as VS Code, Sublime Text, etc.) to enable features such as autocomplete, code navigation, diagnostics (errors and warnings), and refactoring.

[0036] With the rapid development of information technology, software has permeated all sectors of the social economy. In software development and data processing, code writing is a core component. To improve development efficiency, reduce error rates, and alleviate the cognitive load on developers, code completion technology has emerged. From early simple keyword matching to intelligent suggestions based on syntax analysis and context awareness in modern integrated development environments (IDEs), code completion has become a fundamental and crucial tool for improving programmer productivity. In recent years, a number of representative products have emerged, such as Cursor, GitHub Copilot, and Windsurf. Code completion can significantly reduce coding time, help developers remember complex APIs, and effectively avoid spelling errors.

[0037] Among numerous programming languages, Structured Query Language (SQL), as the standard language for interacting with databases, plays an irreplaceable role in data extraction, analysis, business intelligence (BI), and backend services. Almost all data analysts, data scientists, backend engineers, and database administrators (DBAs) are daily users of SQL. However, SQL code completion faces more unique challenges compared to general-purpose programming languages ​​(such as Java and Python): First, it heavily relies on external metadata: the validity of SQL depends heavily on database metadata, including database names, table names, views, field names, functions, stored procedures, etc. An SQL completion tool detached from its specific database context has very limited value.

[0038] Second, the complexity of declarative languages: SQL is a declarative language where users only need to describe "what they want," not "how to get it." This requires the completion system to understand not only the syntax but also the user's query intent and the relationships between the data.

[0039] Third, the diversity of user groups and scenarios: SQL users range from beginners to senior experts, with vastly different coding habits, common table structures, and understanding of business logic. A one-size-fits-all completion strategy is unlikely to meet the needs of users at different levels.

[0040] To address these challenges, current SQL intelligent assistance technology has evolved into two main paradigms: traditional pop-up auto-completion and the emerging AI-generated auto-completion. These two differ significantly in their technical principles, interaction methods, and applicable scenarios, and each faces some bottlenecks that urgently need to be overcome. Pop-up auto-completion is the most common and basic form of assistance in current IDEs and database clients. Its characteristics are: triggered by user input (such as entering keywords, spaces, or periods), the system immediately displays a list of candidate options for the user to choose from. AI-generated auto-completion, on the other hand, leverages a large language model, combined with code context and prompts, to appropriately continue writing when the user pauses editing. Its characteristics include the ability to complete at any position and high flexibility, but relatively high latency and less controllable results.

[0041] The two aforementioned technical paradigms each have their advantages and disadvantages and cannot replace each other. Pop-up auto-completion, due to its immediacy, reliability, and lightweight nature, remains the core auxiliary function most frequently used by developers. Existing SQL pop-up auto-completion technologies mainly fall into two mainstream solutions: The first is auto-completion based on code context segmentation. This solution parses the current code context, segments words using special markers such as spaces, line breaks, punctuation, and keywords, and matches candidate sets based on prefixes entered by the user. However, it is completely detached from the user's current database environment and cannot provide any effective suggestions related to tables or fields, making it extremely impractical. The second is static pre-defined auto-completion. This provides auto-completion by hard-coding SQL keywords (such as SELECT, FROM, WHERE) and general aggregate functions (such as COUNT, SUM), combined with prefixes entered by the user. Due to a lack of personalized understanding of contextual word order and user intent, and also the inability to perceive the database metadata associated with the current SQL, it cannot determine which words the user most likely needs, resulting in low relevance of the recommended candidate words.

[0042] In today's world, where massive amounts of data are increasingly common and the demand for data analysis is surging, a SQL completion tool that can accurately predict user intent and provide highly personalized and logically sorted results is of paramount importance for improving the efficiency of data workers and lowering the barrier to entry for data analysis.

[0043] To address the aforementioned technical problems, this application provides a novel query completion method. It obtains the first query statement being edited by the object and the position information of the input cursor within the first query statement, which is used to retrieve data from a database. Next, based on the first query statement and the position information of the input cursor, it predicts the first word type of the target word element appearing after the input cursor. This first word type belongs to one of N word types, and these N word types include M metadata types (e.g., database name, table name, field name, etc.). If the first word type is a first metadata type, then based on this first metadata type, it retrieves first metadata candidate words for the target word element from the database metadata, where the first metadata type is any one of the M metadata types. Furthermore, based on the first metadata candidate words, a candidate list for the target word element is generated, which is used to complete the target word element. Therefore, this application, by obtaining the query statement being edited by the object and the position of the input cursor, first predicts the word type (i.e., the first word type) of the target word element after the input cursor. When the predicted type (i.e., the first term type) is a metadata type, the corresponding metadata candidate words are retrieved from the database metadata. This mechanism of first predicting the type and then specifically retrieving metadata ensures that the recommendation results not only conform to grammatical norms but also closely match the actual structure of the current database. This avoids the problem of recommendation results being disconnected from database objects in traditional static completion, thereby improving the relevance and accuracy of the completion results. Simultaneously, through term type prediction, this embodiment can identify whether the object currently needs editing a table name, field name, or enumeration value, enhancing the understanding of user intent and thus accurately locating the recall scope. Furthermore, the query statement completion method provided in this embodiment does not depend on specific database products or IDE platforms and can be widely applied to various software tools that support SQL editing, providing a consistent intelligent completion experience for different user groups, demonstrating good versatility and adaptability.

[0044] The query completion method provided in this application can be applied in at least the following scenarios: Scenario 1: The daily data exploration and report development scenarios for data analysts. For example, data analysts frequently need to write SQL queries to extract data from data warehouses or business databases for report generation, behavioral analysis, or business monitoring. They often face complex data models with hundreds of tables and thousands of fields, making it extremely difficult to remember the structure of all tables and the meaning of all fields. Therefore, when writing a SELECT statement, after the data analyst enters the table name prefix, the system, based on the method of this application embodiment, immediately recommends relevant fact tables and dimension tables, prioritizing them based on the user's historical query habits (such as order tables and user tables that the analyst frequently focuses on). When the data analyst enters the WHERE condition, the system, based on the method of this application embodiment, can not only list the fields but also intelligently recommend based on the field's enumerated values ​​or commonly used filtering conditions (such as status = 'completed'), significantly reducing the time spent consulting the data dictionary. This frees data analysts from the tedious memorization of table structures and field searches, allowing them to focus on business logic and data analysis itself, improving the fluency and depth of data exploration.

[0045] Scenario 2 involves ETL (Extract, Transform, Load) and data pipeline development for data development engineers. For example, data development engineers are responsible for building and maintaining ETL tasks, requiring them to write numerous complex SQL scripts involving multi-table JOINs, subqueries, and window functions. The correctness and performance of these scripts are crucial. Therefore, when data development engineers write JOIN conditions, the system, based on the method in this embodiment, can predict and recommend the most likely associated fields (such as user_id) based on the selected left and right tables, and provide a complete ON clause template. When data development engineers write window functions (such as ROW_NUMBER() OVER (PARTITION BY ...)), the system, based on the method in this embodiment, can recommend partitioning and sorting fields based on the context and automatically complete the function syntax. This reduces syntax errors and logical vulnerabilities, improves the development efficiency and code quality of complex SQL, and ensures the stable operation of the data pipeline.

[0046] Scenario 3: Database management and optimization scenarios for Database Administrators (DBAs). For example, DBAs need to write SQL for database object management (such as creating tables and indexes), permission configuration, performance monitoring, and optimization. They need a precise understanding of the current database structure and metadata. Therefore, when DBAs write CREATE TABLE statements, the system, based on the method of this embodiment, can recommend commonly used field types and constraint templates (such as PRIMARYKEY and NOT NULL), and provide naming suggestions based on team standards. When writing GRANT statements, the system, based on the method of this embodiment, can recommend users, roles, and grantable permissions in the current database. When analyzing slow queries, the system, based on the method of this embodiment, can recommend possible index fields based on the SQL context. This improves the efficiency of daily management tasks and reduces operational risks caused by unfamiliarity with metadata or syntax errors.

[0047] Scenario 4: Integrated Development Environment (IDE) and Database Client Scenario. The method described in this application can be deeply integrated with the IDE as a core plugin or built-in function. Users can receive real-time completion and intelligent suggestions while writing SQL. This scenario appeals to a broad user base, ranging from beginners to seasoned experts, who have high demands for response speed, accuracy, and personalization. This solution can serve as an added-value feature to enhance the product's market competitiveness.

[0048] Scenario 5: Cloud Data Platform Scenario. The methods described in this application embodiment can be integrated into the SQL editor of a cloud platform to provide intelligent assistance for cloud data development and analysis. Since cloud platforms typically manage massive amounts of data and multi-tenant environments, they have high requirements for real-time metadata awareness and access control. In this scenario, users need to handle cross-database and cross-schema queries, resulting in a massive amount of metadata. The multi-path retrieval mechanism of this solution (database name, table name, field, enumeration value) can effectively handle this complexity, while combining user / team historical models to achieve personalized recommendations.

[0049] The implementation environment of the embodiments of this application is described below.

[0050] Figure 1 A schematic diagram illustrating the implementation environment of a query statement completion method provided in this application embodiment, as shown below. Figure 1 As shown, the implementation environment includes: terminal device 101 and server 102.

[0051] The terminal device 101 is connected to the server 102 via wired or wireless means.

[0052] In this embodiment, the terminal device 101 is equipped with an editor for a query statement editing system. The server 102 can be understood as the server-side or backend of the query statement editing system. The terminal device 101 is used to interact with an object, receive query statements input by the object, and display a generated candidate list of target terms for the object.

[0053] In some embodiments, the query completion method is performed by server 102. For example, when an object (e.g., a user) edits a first query statement in the editor of a query statement editing system on a terminal device, the terminal device 101 sends a completion request to server 102. This completion request includes the first query statement that the object is editing, and the current position information of the input cursor in the first query statement. Upon receiving the completion request, server 102 parses it to obtain the first query statement that the object is editing and the position information of the input cursor in the first query statement. Then, based on the first query statement and the position information of the input cursor, server 102 predicts the first term type of the target term that appears after the input cursor. This first term type belongs to one of N term types, and these N term types include M metadata types (e.g., database name, table name, field name, etc.). If the first term type is a first metadata type, then server 102, based on this first metadata type, recalls the first metadata candidate word of the target term from the database metadata, where the first metadata type is any one of the M metadata types. Then, server 102 generates a candidate list of target terms based on the first metadata candidate words. This candidate list is used to complete the target term. Next, server 102 sends the generated candidate list of target terms to terminal device 101. Terminal device 101 displays the candidate list of target terms in the editor of the query statement editing system. In this way, the object can select the required candidate term as the target term from the displayed candidate list. Based on the object's selection operation, terminal device 101 inputs the selected target term at the input cursor position, thereby completing the query statement.

[0054] Therefore, this embodiment of the application obtains the query statement being edited by the object and the position of the input cursor, and first predicts the word type (i.e., the first word type) of the target word after the input cursor. When the predicted type (i.e., the first word type) is a metadata type, the corresponding metadata candidate word is recalled from the database metadata. This mechanism of first predicting the type and then recalling metadata in a targeted manner ensures that the recommendation results not only conform to the grammatical rules but also closely fit the actual structure of the current database, avoiding the problem of the recommendation results being disconnected from the database object in traditional static completion, thereby improving the relevance and accuracy of the completion results. At the same time, this embodiment of the application can identify whether the object currently needs to edit a table name, field name, or enumeration value through word type prediction, enhancing the understanding of the user's intent and thus accurately locating the recall range. In addition, the query statement completion method provided by this embodiment of the application does not depend on a specific database product or IDE platform and can be widely used in various software tools that support SQL editing, providing a consistent intelligent completion experience for different user groups, and has good versatility and adaptability.

[0055] In some embodiments, the query statement completion method of this application can be performed by the terminal device 101.

[0056] In some embodiments, the query completion method of this application can be performed by a combination of terminal device 101 and server 102. That is, in the query completion method of this application, some steps are performed by terminal device 101 and some steps are performed by server 102. For example, the step of predicting the first word type of the target word is performed by terminal device 101, while the steps of metadata retrieval and candidate list generation are performed by server 102.

[0057] In some embodiments, the terminal device 101 includes, but is not limited to, desktop computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices may be devices equipped with cameras and display devices, such as smart speakers, smart TVs, smart air conditioners, and smart in-vehicle systems. Portable wearable devices may be devices equipped with cameras and display devices, such as smartwatches, smart bracelets, and head-mounted devices. Terminal devices are often equipped with display devices, which may also be monitors, displays, touchscreens, etc., and touchscreens may also be touchscreens, touch panels, etc.

[0058] In some embodiments, the server 102 may be one or more servers. When there are multiple servers, at least two servers may be used to provide different services, and / or at least two servers may be used to provide the same service, such as providing the same service in a load-balanced manner. This application embodiment does not limit this. The server may be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The server may also be a node in a blockchain.

[0059] It should be noted that the implementation environment of this application embodiment includes, but is not limited to, Figure 1 As shown.

[0060] The technical solutions of the embodiments of this application will be described in detail below through some examples. The following embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments.

[0061] Figure 2 This is a flowchart illustrating a query completion method provided in an embodiment of this application. The execution entity of this embodiment can be a device with completion functionality, such as a query completion device. This query completion device can be the one described above. Figure 1 The server shown is 102, or Figure 1 The terminal device 101 shown, or Figure 1 The system consists of terminal device 101 and server 102 shown. For ease of description, the following embodiments use a computing device as the execution subject to illustrate the method of this application.

[0062] like Figure 2 As shown, the query statement completion method of this application embodiment includes the following steps: S101. Obtain the first query statement that the object is currently editing, and input the position information of the cursor in the first query statement.

[0063] The first query statement is used to retrieve data from the database.

[0064] It should be noted that the data used in executing the embodiments of this application, and the process of obtaining this data, comply with the relevant laws and regulations.

[0065] The query statement completion method of this application can be applied to any scenario where data is queried from a database using a query statement.

[0066] In some embodiments of this application, a query statement editing system editor is installed on the terminal device. This editor can be understood as a piece of software code that can run on any terminal device, allowing an object (e.g., a user) to edit query statements. It should be noted that this editor can have a standalone client or be integrated into other platforms, sharing the client with other platforms.

[0067] The query statement editing system in this application embodiment has a pop-up auto-completion capability. For example... Figure 3 As shown, a pop-up recommendation option is displayed in the editing interface. The user can choose to check this option to activate the pop-up auto-completion capability. This way, when the user edits the first query statement, a candidate list of the target term (i.e., the term that appears after the cursor is entered) can be generated in real time and displayed via a pop-up. This candidate list includes possible candidate terms for the target term, and the user can select the desired term from the list, for example, by quickly selecting it using the Enter or Tab key. The query statement completion method of this application mainly involves the process of generating a candidate list of target terms.

[0068] Current pop-up auto-completion methods mostly rely on built-in keywords (such as the keyword "and") and function auto-completion. The recommended candidate words are completely detached from the user's current database environment and cannot provide any effective suggestions related to the database, resulting in low accuracy and poor completion effect.

[0069] The query completion method provided in this application takes into account database metadata when generating a candidate list of target terms. It can not only complete keywords and functions, but also complete database metadata such as database names, tables, and fields. This avoids the problem of the recommendation results being disconnected from database objects in traditional static completion, thereby improving the accuracy of the generated candidate list and enhancing the completion effect of the query statement.

[0070] In the database field, database metadata refers to "data about data," that is, information describing the database structure. It mainly includes: database information (the names of each database), table information (all table names and view names in the database), field information (column names, data types (e.g., int, varchar), whether it is a primary key, and whether it can be nullable) for each table), and constraints (primary key constraints, foreign key constraints, and index information). For a concrete example, suppose there is an e-commerce database whose metadata includes the following tables: users, orders, and products; the fields in the users table (users) are: id, username, email, and created_at; and the fields in the orders table (orders) are: order_id, user_id, product_id, amount, and order_date.

[0071] In this embodiment of the application, when the computing device executes this embodiment of the application, it first obtains the first query statement that the object is editing, and the position information of the input cursor in the first query statement.

[0072] In one example, if the computing device is a server, such as Figure 4 As shown, when an object is editing the first query statement, the terminal device obtains the first query statement that the object is currently editing, as well as the position information of the input cursor within the first query statement. The first query statement includes the query statements that the object has already edited. For example... Figure 4 The object shown is editing the input content under keywords such as SELECT (specifies which columns to retrieve data from the database table), FROM (specifies which table the data comes from), WHERE (sets filtering conditions to select rows that meet specific conditions), and ORDER BY (sorts the result set according to one or more columns. The default is ascending order). For example... Figure 4 As shown, the cursor position in the first query statement is after "pcg_olachat." under the FROM keyword. Next, the terminal device sends the first query statement being edited, along with the cursor position within that query statement, to the server.

[0073] In one example, if the computing device is a terminal device, then when the terminal device detects that the object is editing the first query statement, the terminal device will know the first query statement that the object is currently editing, and the position information of the input cursor in the first query statement.

[0074] It should be noted that the process of obtaining the first query statement being edited by the object and the position information of the input cursor in the query statement in this embodiment is a real-time repetitive operation. That is, during each editing operation of the object, the position information of the first query statement and the input cursor under each editing operation is obtained. Under different editing operations, at least one of the obtained first query statement and input cursor position information is different. In this embodiment, the editing operation of the first query statement includes operations such as input, deletion, and movement.

[0075] In this embodiment of the application, the computing device, based on the above steps, obtains the first query statement that the object is editing and the position information of the cursor in the first query statement, and then executes the following step S102.

[0076] S102. Based on the first query statement and the position information of the input cursor, predict the first word type of the target word that appears after the input cursor.

[0077] Among them, the first lexical type belongs to one of the N lexical types. The N lexical types include M metadata types, where N is a positive integer greater than 1 and M is a positive integer greater than 1 and less than N.

[0078] In this embodiment, after the computing device obtains the first query statement being edited by the object and the position information of the input cursor in the first query statement, it first predicts, based on the first query statement and the position information of the input cursor, which of the N word types the target word appearing after the input cursor will be. For ease of description, the word type of the target word predicted in this step is denoted as the first word type.

[0079] In other words, to improve the accuracy of candidate terminology recommendations for target terms, this application embodiment considers not only the keywords of the query statement (such as SELECT, FROM, WHERE, and), but also database metadata when generating candidate terminology for the target terminology. Based on this, this application embodiment divides the terminology that may be involved in query statement completion into N different types of terminology, including M metadata types and NM non-metadata types.

[0080] For example, the M types of metadata may include database name, table name, field name, enumeration value, etc.

[0081] For example, NM non-metadata types may include keyword types, function types, etc.

[0082] Therefore, to improve the accuracy and speed of candidate word list determination, this embodiment first predicts the lexical type of the target word after the input cursor. This mechanism of predicting the type first and then recalling metadata in a targeted manner ensures that the recommendation results not only conform to grammatical norms but also closely match the actual structure of the current database, avoiding the problem of recommendation results being disconnected from database objects in traditional static completion, thereby improving the relevance and accuracy of the completion results. Simultaneously, through lexical type prediction, this embodiment can identify whether the object currently needs editing a table name, field name, or enumeration value, enhancing the understanding of user intent and thus accurately locating the recall scope.

[0083] The following describes the process by which a computing device predicts the first word type of the target word that appears after the input cursor, based on the first query statement and the position information of the input cursor.

[0084] This application does not limit the specific method by which the computing device predicts the first word type of the target word that appears after the input cursor based on the first query statement and the position information of the input cursor.

[0085] In some embodiments, the present application embodiments may pre-train a type prediction model. The computing device inputs the first query statement and the position information of the input cursor into the type prediction model, and the type prediction model can predict the first word type of the target word.

[0086] In some embodiments, the computing device can predict the first term type of the target term through the following steps S102-A to S102-D: S102-A: Based on the position information of the input cursor, extract the current query segment where the input cursor is located from the first query statement; S102-B: Insert a preset placeholder after the input cursor; S102-C: Perform syntax parsing on the current query segment with the inserted preset placeholder, and predict the word type to which the preset placeholder belongs; S102-D. Determine the first lexical type of the target lexical based on the lexical type to which the preset placeholder belongs.

[0087] In the embodiments of this application, such as Figure 4 As shown, the first query statement may contain multiple executable query segments. In order to improve the prediction speed, the computing device extracts the current query segment where the input cursor is located from the first query statement based on the position information of the input cursor, processes the current query segment, and determines the first word type of the target word.

[0088] In some examples, if the current query fragment is too long, the computing device analyzes the current query fragment to truncate it, resulting in a query statement fragment whose length meets the preset length requirement.

[0089] In some examples, to improve prediction accuracy, the computing device first validates the first query statement to determine whether its query logic and syntax meet the corresponding requirements. After the first query statement passes validation, the device predicts the first term type of the target term based on that first query statement.

[0090] In this embodiment of the application, in order to predict the first word type of the target word, after extracting the current query segment where the input cursor is located from the first query statement, a preset placeholder is inserted after the input cursor.

[0091] In this application embodiment, no specific type of the preset placeholder is selected. It can be any special string that will not conflict with normal SQL syntax, such as "___CURSOR___", "__ANTLR_PLACEHOLDER__", "¥CURSOR¥", etc.

[0092] For example, if the current query is "SELECT name FROM user WHERE age>", the input cursor is positioned after ">", waiting for a value or column name to be entered. Assuming the default placeholder is "___CURSOR___", then the current query with the default placeholder inserted would be "SELECT name FROM user WHERE age>___CURSOR___".

[0093] Next, the computing device performs syntax parsing on the current query fragment with the preset placeholder inserted, and predicts the term type to which the preset placeholder belongs.

[0094] In one example, a computing device can use a parser to parse the current query fragment containing predefined placeholders, obtaining an Abstract Syntax Tree (AST). It then locates the node containing the predefined placeholders and infers its type based on the node's role within the AST. Specifically, the computing device inputs the current query fragment with the predefined placeholders into the parser to generate the AST. For example, the parser scans characters from left to right and combines them into tokens according to predefined lexical rules (usually described by regular expressions), outputting an ordered stream of tokens. Next, based on the query's syntax rules, these tokens are organized into a hierarchical AST. Then, the AST is traversed, finding all leaf nodes or identifier nodes and matching them against the predefined placeholders. Because the predefined placeholders are unique, the node containing them can be quickly located. The device then observes the node's parent node and context within the AST to determine its syntactic role. The common correspondences are as follows: If the parent node is TableRef (table reference), the term type of the default placeholder is the table name; if the parent node is ColumnRef (column reference), the term type of the default placeholder is the field name; if the parent node is DatabaseName (database name), the term type of the default placeholder is the database name; if the parent node is FunctionCall (function call), the term type of the default placeholder is the function name; if the parent node is near Literal (literal) and the placeholder appears to the right of operators such as IN and =, the term type of the default placeholder is the enumeration value. For example, the current query fragment that inserts the default placeholder is "SELECT name FROM ___CURSOR___". In the constructed abstract syntax tree, the default placeholder "___CURSOR___" is located under TableRef in the FROM clause, therefore the term type of the default placeholder is the table name.

[0095] In some embodiments, the query language has different dialects, such as MySQL and PostgreSQL. Keywords and functions may differ for different query dialects (e.g., SQL dialects), but most are universal. In this application embodiment, the preset candidate word set is specifically set according to different dialects. Based on this, when the computing device performs syntax parsing based on the current query fragment with inserted preset placeholders and predicts the lexical type to which the preset placeholders belong, it also considers the query dialect currently used by the object. For example, the computing device inputs the current query fragment with inserted preset placeholders and the dialect type of the query statement used by the object into the syntax parser to generate an abstract syntax tree (AST).

[0096] Then, based on the word type to which the preset placeholder belongs, the first word type of the target word is determined. For example, the word type to which the preset placeholder belongs is determined as the first word type of the target word.

[0097] S103. If the first lexical type is the first metadata type, then based on the first metadata type, recall the first metadata candidate word of the target lexical from the database metadata.

[0098] The first metadata type is any one of the M metadata types.

[0099] In this embodiment of the application, after determining the first word type of the target word based on the above steps, the computing device determines whether the first word type belongs to one of the M metadata types. If the first word type is one of the M metadata types, then based on the metadata type, the first metadata candidate word of the target word is retrieved from the database metadata.

[0100] Therefore, in this embodiment, when the target lexical type is a metadata type, the corresponding metadata candidate word is retrieved from the database metadata based on that metadata type. This mechanism of first predicting the type and then selectively retrieving metadata ensures that the recommendation results not only conform to grammatical norms but also closely fit the actual structure of the current database, avoiding the problem of recommendation results being disconnected from database objects in traditional static completion, thereby improving the relevance and accuracy of the completion results.

[0101] For ease of description, if the first lexical type is a metadata type, then the metadata type is referred to as the first metadata type, which is any one of the M metadata types.

[0102] The following describes the specific process by which a computing device retrieves candidate words of the first metadata of a target word from the database metadata based on the first metadata type.

[0103] This application embodiment does not limit the specific method by which the computing device recalls first metadata candidate words of the target word from the database metadata based on the first metadata type.

[0104] In some embodiments, the computing device can recall metadata candidate words corresponding to the first metadata type from the database metadata, and then record the recalled metadata candidate words as the first metadata candidate words of the target word. For example, when the first metadata type is a database, the database table names in the database metadata are recalled as the first metadata candidate words of the target word. As another example, if the first metadata type is a table name, the table names in the aforementioned database metadata are recalled.

[0105] In some embodiments, based on the first metadata type, recalling the first metadata candidate word of the target lexical from the database metadata includes the following steps S103-A: S103-A: Based on the first metadata type and the first query statement, retrieve the first metadata candidate word of the target word from the database metadata.

[0106] In this implementation, to improve the accuracy and reduce the workload of retrieving the first metadata candidate words for the target lexical, the computing device, when retrieving the first metadata candidate words for the target lexical from the database metadata based on the first metadata type, also considers the first query statement that the object has been edited. This narrows the recall scope and improves recall accuracy by parsing the first query statement.

[0107] In this embodiment, the M metadata types include database name, table name, field name, and enumeration value. The process of recalling the first metadata candidate words for the target term is described below when the first metadata type is database name, table name, field name, or enumeration value.

[0108] In some embodiments, if the first metadata type is a database name, then the first metadata candidate words include candidate database names. In this case, the specific process of recalling the first metadata candidate words of the target term includes at least the following methods: Method 1: Retrieve the database name from the database metadata. Retrieving the database name from the database metadata includes at least the following cases: In one scenario, the computing device checks the first query statement. If, based on the first query statement, it detects that the object lacks a database name prefix, it retrieves all database names included in the database metadata. For example, if the object lacks a database name prefix, it retrieves all database names included in the database metadata, or it retrieves a predetermined number of database names from the database metadata.

[0109] In one scenario, the computing device detects a first query statement. If, based on the first query statement, an object input database name prefix is ​​detected, then, based on that database name prefix, it retrieves database names with that prefix from the database names included in the database metadata.

[0110] In this method 1, the computing device determines candidate database names for the target word based on the recalled database names. For example, the recalled database names are selected as candidate database names for the target word. Another example is selecting a preset number of database names with the highest popularity values ​​from the recalled database names and determining them as candidate database names for the target word.

[0111] Method 2 involves the computing device acquiring the names of all databases used by the target within a historical time period, along with the popularity value of each database name. Based on this popularity value, a predetermined number of database names with the highest popularity values ​​are selected from the database names used by the target within the historical time period and identified as candidate database names for the target term.

[0112] Method 3: The computing device retrieves some database names from the database metadata using Method 1 described above. Specifically, if the object does not input a database name prefix based on the first query statement, it retrieves all database names included in the database metadata; if the object inputs a database name prefix based on the first query statement, it retrieves database names whose prefix is ​​the database name prefix from the database names included in the database metadata. Simultaneously, using Method 2 described above, it obtains all database names used by the object during the historical time period, as well as the popularity value of each used database name. Then, based on the retrieved database names, the used database names, and the popularity value of the used database names, candidate database names for the target term are determined. For example, based on the popularity value of the used database names, the retrieved database names and the used database names are ranked, and a predetermined number of database names with the highest popularity values ​​are selected as candidate database names for the target term.

[0113] In some embodiments, if the first metadata type is a table name, then the first metadata candidate words include candidate table names. In this case, the specific process of recalling the first metadata candidate words of the target term includes at least the following methods: Method 1: Retrieve the table name from the database metadata. Retrieving the table name from the database metadata includes at least the following cases: In one scenario, the computing device detects the first query statement and, based on the first query statement, detects that the object has entered a database name but has not entered a table name prefix, then recalls the table names under the database name entered by the object.

[0114] In one scenario, the computing device detects a first query statement and, if it detects an object input database name and a table name prefix based on the first query statement, it retrieves table names with the table name prefix from each table under the object input database name in the database metadata.

[0115] In this method 1, the computing device determines candidate table names for the target word based on the recalled table names. For example, the recalled table names are selected as candidate table names for the target word. Another example is selecting a preset number of table names with the highest popularity values ​​from the recalled table names and determining them as candidate table names for the target word.

[0116] In one possible implementation, when recalling the table name as described above, if the object has already entered the relevant field, the table name of the table including that field can be recalled based on that field.

[0117] Method 2 involves the computing device acquiring the table names used by the object during a historical time period, as well as the popularity value of each table name. Based on the popularity value, a predetermined number of table names with the highest popularity value are selected from the table names used by the object during the historical time period and determined as candidate table names for the target word.

[0118] Method 3: The computing device retrieves some table names from the database metadata using Method 1 described above. Specifically, if the first query statement detects that the object entered a database name but did not enter a table name prefix, the device retrieves all table names under the database name entered by the object from the database metadata. If the first query statement detects that the object entered both a database name and a table name prefix, the device retrieves table names with the prefix "table name prefix" from the tables under the database name entered by the object from the database metadata. Simultaneously, using Method 2 described above, the device obtains all table names used by the object during the historical time period, as well as the popularity values ​​of each used table name. Then, based on the retrieved table names, the used table names, and the popularity values ​​of the used table names, candidate table names for the target term are determined. For example, based on the popularity values ​​of the used table names, the retrieved table names and the used table names are ranked, and a predetermined number of table names with the highest popularity values ​​are selected as candidate table names for the target term.

[0119] In some embodiments, if the first metadata type is a field, then the first metadata candidate words include candidate fields. In this case, the specific process of recalling the first metadata candidate words of the target term includes at least the following methods: Method 1: Retrieve fields from database metadata. Retrieving fields from database metadata includes at least the following: In one scenario, the computing device detects a first query statement and, based on the first query statement, detects that the object has entered a table name but has not entered any field prefixes. Then, it retrieves the fields under the table name entered by the object from the database metadata.

[0120] In one scenario, the computing device detects a first query statement, and if, based on the first query statement, it detects an object input table name and a field prefix, it retrieves fields whose prefix is ​​the specified field from the fields under the object input table name in the database metadata.

[0121] In this method 1, the computing device determines candidate fields for the target word based on the recalled fields mentioned above. For example, the recalled fields are determined as candidate fields for the target word. Another example is selecting a preset number of fields with the highest popularity values ​​from the recalled fields and determining them as candidate fields for the target word.

[0122] Method 2 involves the computing device acquiring the fields used by the object during a historical time period, along with the popularity value of each used field. Based on these popularity values, a predetermined number of fields with the highest popularity values ​​are selected from the fields used by the object during the historical time period and identified as candidate fields for the target term.

[0123] Method 3: The computing device retrieves certain fields from the database metadata using Method 1 described above. Specifically, if the object inputs a table name but no field prefix based on the first query statement, it retrieves all fields under the table name input by the object from the database metadata. If the object inputs both a table name and a field prefix based on the first query statement, it retrieves fields with the field prefix from the fields under the table name input by the object from the database metadata. Simultaneously, using Method 2 described above, it obtains all fields used by the object during the historical time period, as well as the popularity value of each used field. Then, based on the retrieved fields, the used fields, and the popularity values ​​of the used fields, candidate fields for the target term are determined. For example, based on the popularity values ​​of the used fields, the retrieved fields and the used fields are ranked, and a predetermined number of fields with the highest popularity values ​​are selected as candidate fields for the target term.

[0124] In some embodiments, if the first metadata type is an enumeration value, then the first metadata candidate words include candidate enumeration values. In this case, the specific process of recalling the first metadata candidate words of the target term includes at least the following methods: Method 1: The computing device detects the first query statement. If, based on the first query statement, it detects that an object has an input field and that the input field is an enumeration type, it retrieves the enumeration value list of the input field from the database metadata based on the table name and database name to which the input field belongs.

[0125] In this method 1, the computing device determines candidate enumeration values ​​for the target word based on the aforementioned recalled enumeration value list. For example, the aforementioned recalled enumeration value list is used as the candidate enumeration values ​​for the target word. Another example is selecting a preset number of enumeration values ​​with the highest popularity values ​​from the aforementioned recalled enumeration value list and determining them as candidate enumeration values ​​for the target word.

[0126] Method 2: The computing device obtains the enumeration values ​​used by the object during the historical time period, as well as the popularity value of each used enumeration value. Then, based on the popularity value, a preset number of enumeration values ​​with the highest popularity values ​​are selected from the enumeration values ​​used by the object during the historical time period to determine the candidate enumeration values ​​of the target word.

[0127] Method 3: The computing device retrieves an enumeration value list from the database metadata using Method 1 described above. Specifically, if an object has an input field detected based on the first query statement, and that input field is of enumeration type, the device retrieves the enumeration value list for that input field from the database metadata based on the table name and database name to which the input field belongs. Simultaneously, using Method 2 described above, the device obtains each enumeration value used by the object within a historical time period, as well as the popularity value of each used enumeration value. Then, based on the retrieved enumeration value list, the used enumeration values, and the popularity values ​​of each used enumeration value, candidate enumeration values ​​are determined. For example, based on the popularity values ​​of each used enumeration value, the enumeration values ​​in the retrieved enumeration value list and the used enumeration values ​​are sorted, and a predetermined number of enumeration values ​​with the highest popularity values ​​are selected as candidate enumeration values ​​for the target term.

[0128] In this embodiment of the application, if the computing device predicts, based on the first query statement and the position information of the input cursor, that the first lexical type of the target lexical appearing after the input cursor is the first metadata type, then, based on the above steps, the first metadata candidate word of the target lexical is recalled. Next, the following step S104 is executed.

[0129] S104. Based on the first metadata candidate words, generate a candidate list of target words.

[0130] The candidate list is used to complete the target word.

[0131] In this embodiment of the application, after determining the first metadata candidate word of the target word based on the above steps, the computing device generates a candidate list of the target word based on the first metadata candidate word.

[0132] This application embodiment does not limit the specific method by which the computing device generates a candidate list of target lexical units based on the first metadata candidate words.

[0133] In some embodiments, the computing device will sort the first metadata candidate words of the recalled target words to generate a candidate list of target words.

[0134] In some embodiments, to further improve the accuracy of the candidate list generation, the computing device generates a candidate list of target lexical units based on the first metadata candidate words, including the following steps S104-A and S104-B: S104-A: Through the trained word order prediction model, the first word sequence and the first word type sequence are processed to obtain the probability value of the target word belonging to each word type, and the word prediction value of the target word under each word type. S104-B: Using the trained word order prediction model, the first query statement after masking is predicted to obtain the probability value of the target word belonging to each of the N word types, and the word prediction value of the target word under each word type. S104-C, based on the first metadata candidate words of the target word, the probability value of the target word belonging to each word type, and the word prediction value of the target word under each word type, generate a candidate list of the target word.

[0135] In this embodiment of the application, a word order prediction model is also trained. This word order prediction model is used to predict the probability value of the target word belonging to each of the N word types, as well as the word prediction value of the target word under each word type.

[0136] The training process of this word order prediction model is described below.

[0137] In some embodiments, the word order prediction model can be trained through the following steps 1 to 4: Step 1: Obtain training samples, which include a training query statement; Step 2: Perform word segmentation on the training query statement, and mask the words in the segmented training query statement based on random positions to obtain the masked training query statement. Step 3: Using the word order prediction model, perform prediction processing on the masked training query statement to obtain the probability value of the word element at the random position belonging to each word element type, and the word element prediction value of the word element at the random position under each word element type. Step 4: Based on the probability value of a word at a random position belonging to each word type and the word prediction value of a word at a random position under each word type, determine the model loss value, and train the word order prediction model based on the model loss value to obtain the trained word order prediction model.

[0138] It should be noted that the computing device for training the word order prediction model and the technical device for executing the query statement completion method described above can be the same device or different devices. For ease of description, the computing device for training the word order prediction model will be referred to as the training device.

[0139] Before training the model, multiple training samples are prepared to form a training sample set. Each training sample includes a query statement, which is designated as the training query statement. In this embodiment, to improve the model's training performance, some training samples in the training sample set contain query statement fragments, while others contain complete query statements, such as complete SQL text.

[0140] This application treats query statements as a special kind of "language" and proposes multiple modeling methods combining lexical types and special keywords to learn the probabilistic relationships between specific word and type sequences. The model is trained based on historical query corpora from specific users, teams, or projects. For example, the model can learn that a field should follow a SELECT statement, followed by FROM and WHERE.

[0141] It should be noted that the specific process of training the word order prediction model using each training sample in the training sample set is basically the same. For ease of description, we will use a single training sample as an example here.

[0142] Specifically, such as Figure 5 As shown, when the training device uses the training sample for model training, it first performs word segmentation on the training query statement included in the training sample, and then masks the words at random positions in the segmented training query statement to obtain the masked training query statement. For example, the word at the nth or mth position in the training query statement is masked (i.e., obscured) to obtain the masked training sample. Then, the word order prediction model is used to predict the masked training query statement to obtain the probability value of the word at the random position belonging to each word type, and the word prediction value of the word at the random position under each word type. For example, Figure 5 As shown, the training query statement after the mask is input into the word order prediction model. The word order prediction model predicts the probability value of the word at the random position belonging to each of the N word types, as well as the word prediction value of the word at the random position under each word type.

[0143] In some embodiments, step 3 above uses a word order prediction model to predict the masked training query statement, obtaining the probability value of a word at a random position belonging to each word type, and the word prediction value of a word at a random position under each word type, including the following steps 31 to 33: Step 31: Generalize the metadata-type tokens in the masked training query statement to the corresponding unified tokens to obtain the second token sequence; Step 32: Determine the lexical type corresponding to each lexical in the second lexical sequence except for the mask, and obtain the second lexical type sequence; Step 33: Using the word order prediction model, perform prediction processing on the second word sequence and the second word type sequence to obtain the probability value of the word at the random position belonging to each word type, and the word prediction value of the word at the random position under each word type.

[0144] In this implementation, metadata-type terms in the masked training query are generalized to corresponding unified terms to obtain a second term sequence. This is because metadata-type terms, such as database names, table names, field names, and enumerated values, are almost impossible to exhaustively list. It's impossible to train and predict using a finite vocabulary. Even assuming that historical SQL queries are exhaustively listable, the number would be enormous, making effective training impossible and unable to handle future new terms. Therefore, this embodiment of the application generalizes metadata-type terms. When a metadata-type term is encountered, it is generalized to the corresponding unified term; for example, table names are generalized to unified terms.

[0145] <column>FROM< / column> , all kinds of fields are generalized into a unified token <COLUMN>. For tokens such as keywords and functions that can be enumerated, the original semantics are retained. For example, the training query statement is "SELECT name FROM users", after generalization, it becomes "SELECT

[0146]

[0147] <column>', 'FROM', '< / column> ". Then, determine the token type corresponding to each token in the second token sequence except for the mask, and obtain the second token type sequence. For example, for each token in the second token sequence except for the mask, the training device determines which token type in the N token types this token belongs to, and then obtains the second token type sequence corresponding to this second token sequence. These N token types include: database name, table name, field, enumeration value, keyword, function, etc. In some embodiments, it is also possible to first perform generalization processing on the tokenized training query statement and then perform masking processing. For example, assume that the training query statement included in the training sample is: SELECT name FROM users WHERE age>18. After tokenizing this training query statement, the token sequence obtained is: ['SELECT', 'name', 'FROM', 'users', 'WHERE', 'age', '>', '18']. Generalize the tokens belonging to the metadata type in the above token sequence into the corresponding unified tokens, and obtain the token sequence: ['SELECT', ' <column>The token type is determined for each token in the token sequence, resulting in the token type sequence: ['KEYWORD', 'COLUMN', 'KEYWORD', 'TABLE', 'KEYWORD', 'COLUMN', 'OPERATOR', 'CONSTANT']. Then, the training device masks the tokens at random positions in the above token sequence to obtain a second token sequence, and masks the token types at those random positions in the above token type sequence to obtain a second token type sequence. For example, for the above token sequence ['SELECT', '... ... <column>', 'FROM', '< / column> < / column> ', 'WHERE', ' <column>The word character at the second position (or any other position, this is just an example) in ', '>', '18'] <column>' is masked to obtain the second token sequence: ['SELECT', 'MASK', 'FROM', '< / column> < / column> ', 'WHERE', ' <column>', '>', '18']. And mask the second lexical type 'COLUMN' in the above lexical type sequence ['KEYWORD', 'COLUMN', 'KEYWORD', 'TABLE', 'KEYWORD', 'COLUMN', 'OPERATOR', 'CONSTANT'] (for example, mask it with the MASK string), to obtain the second lexical type sequence as: ['KEYWORD', 'MASK', 'KEYWORD', 'TABLE', 'KEYWORD', 'COLUMN', 'OPERATOR', 'CONSTANT'].

[0148] Then, the word order prediction model is used to process the second word sequence and the second word type sequence to predict the probability value of the word at a random position in the training query statement belonging to each of the N word types, as well as the word prediction value of the word at the random position under each word type.

[0149] This application does not limit the specific network structure of the word order prediction model. In some embodiments, the word order prediction model of this application is a neural network model that can perform bidirectional context modeling of the sequence, such as a Transformer-based model.

[0150] In some embodiments, such as Figure 6A As shown, the word order prediction model includes an embedding module and a prediction model. The training device inputs the second word sequence and the second word type sequence into the embedding module. This module extracts the embedding information of the second word sequence, for example, mapping the words in the second word sequence to dense vectors. Similarly, the embedding module extracts the embedding information of the second word type sequence, for example, mapping each word type (such as KEYWORD, COLUMN) in the second word type sequence to another vector. Then, the embedding information of the second word sequence and the second word type sequence are fused to obtain fused embedding information, which is recorded as the fused embedding information of the training query statement. Optionally, positional information can also be added during the feature encoding process to enable the model to perceive the sequence order. For example, the positional information of the second word sequence and the positional information of the second word type sequence are extracted. Then, the embedding information and positional information of the second word sequence, as well as the embedding information and positional information of the second word type sequence, are fused to obtain the fused embedding information of the training query statement. The feature fusion method can be concatenation or addition, etc.

[0151] Next, as Figure 6A As shown, the training device inputs the fusion embedding information of the training query statement into the prediction module. The prediction module performs prediction processing on the fusion embedding information to obtain the probability value of the word at a random position in the training query statement belonging to each word type, and the word prediction value of the word at the random position under each word type.

[0152] In the model training process of this application embodiment, the training device, based on the above steps, predicts the probability value of the word at a random position in the training query statement belonging to each word type, and the word prediction value of the word at the random position under each word type. Then, it executes step 4 above to determine the model loss value based on the probability value of the word at the random position in the training query statement belonging to each word type, and the word prediction value of the word at the random position under each word type.

[0153] This application does not limit the specific method for determining the model loss value in its embodiments.

[0154] In some embodiments, by Figure 6A and Figure 6B As can be seen, the word order prediction model in this application embodiment has two prediction branches: a lexical type prediction branch and a lexical prediction value prediction branch. Therefore, the model loss value in this application embodiment includes at least a lexical type prediction loss value and a word prediction loss value. Based on this, the training device can determine the lexical type prediction loss value based on the probability value of the lexical at a random position in the training query statement predicted by the model to belong to each lexical type, and determine the word prediction loss value based on the lexical prediction value of the lexical at that random position under each lexical type.

[0155] In one possible implementation, the training device determines the target lexical type with the highest probability value from the probability values ​​of lexical units at random positions belonging to each lexical type. Based on the probability value of the lexical unit at that random position belonging to the target lexical type, and the ground truth value of the lexical type of the lexical unit at that random position in the training query, the training device determines the lexical type prediction loss value of the model. Simultaneously, based on the lexical prediction value of the lexical unit at that random position under the target lexical type, and the ground truth value of the lexical unit at that random position in the training query, the training device determines the lexical prediction loss value. Finally, based on the above lexical type prediction loss value and the above lexical prediction loss value, the model loss value is determined.

[0156] For example, the sum of the above word type prediction loss value and the above word prediction loss value is determined as the model loss value.

[0157] For example, the weighted sum of the above word type prediction loss value and the above word prediction loss value is determined as the model loss value.

[0158] In this embodiment, the training device determines the model loss value based on the above steps, and then adjusts the parameters in the word order prediction model based on this model loss value. After multiple rounds of training, a trained word order prediction model can be obtained. In some embodiments, such as... Figure 6B As shown, during model training, the prediction module in the word order prediction model is trained, while the embedding module is not trained. In other words, the embodiments of this application can use the pre-trained embedding module as the embedding module in the word order prediction model.

[0159] This application's embodiments address the problem that traditional pre-set recommendations and editor recommendations cannot personalize word order information through a word order prediction model, making recommended candidate words more relevant. Simultaneously, by using a model for sequence modeling, compared to statistical modeling, it avoids the problem of sequence combination explosion, can model longer sequences, and employs bidirectional sequence modeling to ensure modeling of the preceding and following context. Furthermore, this application's embodiments generalize to lexical units belonging to metadata types and further model both the lexical units and lexical unit types simultaneously, solving the problem of the inability to exhaustively enumerate metadata-type lexical units, effectively reducing training difficulty, and modeling lexical unit types helps retain more information during sorting.

[0160] The training process of the word order prediction model has been introduced above.

[0161] The specific implementation process of S104-A to S104-C is described below.

[0162] Specifically, the computing device first performs word segmentation on the first query statement based on semantic information.

[0163] It should be noted that if the input cursor is preceded by a prefix of the object input, in one example, the prefix and the input cursor are separated into two different segments, and in another example, the prefix and the input cursor can be divided into one segment.

[0164] Next, the computing device performs word masking on the tokens in the first query statement after word segmentation based on the position information of the input cursor, thus obtaining the masked first query statement. For example, if the input cursor is a token in the first query statement after word segmentation, the input cursor can be masked to obtain the masked first query statement.

[0165] Then, the computing device uses the trained word order prediction model to predict the first query statement after masking, obtaining the probability value of the target word belonging to each of the N word types, and the word prediction value of the target word under each word type. For example, Figure 7 As shown, the first query statement after the mask is input into the trained word order prediction model. The trained word order prediction model predicts the probability value of the target word belonging to each of the N word types, as well as the word prediction value of the target word under each word type.

[0166] In some embodiments, in S104-B above, the trained word order prediction model is used to predict the first query statement after masking to obtain the probability value of the target word belonging to each of the N word types, and the word prediction value of the target word under each word type, including the following S104-B1 to S104-B3: S104-B1. Generalize the metadata-type tokens in the first query statement after masking to the corresponding unified tokens to obtain the first token sequence. S104-B2. Determine the word type corresponding to each word in the first word sequence except for the mask, and obtain the first word type sequence; S104-B3. The trained word order prediction model is used to process the first word sequence and the first word type sequence to obtain the probability value of the target word belonging to each word type, as well as the word prediction value of the target word under each word type.

[0167] In this implementation, the computing device generalizes the metadata-type tokens in the masked first query statement to the corresponding unified tokens, thus obtaining a first token sequence. For example, it generalizes various table names to unified tokens.< / column> ', 'WHERE', '

[0168]

[0169]

[0170]

[0171] Figure 8

[0172] Figure 8

[0173]

[0174]

[0175]

[0176]

[0177]

[0178]

[0179]

[0180]

[0181]

[0182]

[0183] <column>The probability of the type is 0.95, the probability of belonging to the keyword AND is 0.03, and the probability of belonging to the function COUNT is 0.02. Next, the computing device calculates the probability based on the target term belonging to the field. <column>The probability value for the type is 0.95, and the probability values ​​for each candidate field ['amount', 'status', 'id', 'user_id', 'product_id'] of the target word are also 0.95. Furthermore, based on the probability values ​​of each candidate field ['amount', 'status', 'id', 'user_id', 'product_id'] of the target word being 0.95, the probability of the target word belonging to the keyword AND being 0.03, and the probability of the target word belonging to the function COUNT being 0.02, the candidate fields ['amount', 'status', 'id', 'user_id', 'product_id'], the keyword AND, and the function COUNT are sorted to obtain the candidate list of the target word. For example, the candidate list for the target term is: ['amount', 'status', 'id', 'user_id', 'product_id'], the keyword AND, and the function COUNT. The candidate fields in ['amount', 'status', 'id', 'user_id', 'product_id'] can be sorted based on their respective popularity values, thus obtaining the candidate list for the target term as: amount, status, id, user_id, product_id, AND, COUNT.

[0184] In some embodiments, to further improve the accuracy of the candidate list determination, the computing device reads the maximum probability value from the probability values ​​of the target word belonging to M metadata types from the probability values ​​of the target word belonging to N word types determined above. If the second metadata type corresponding to the maximum probability value is different from the first metadata type, then based on the second metadata type, the second metadata candidate words of the target word are recalled from the database metadata. The specific recall process is basically the same as the specific process of the computing device recalling the first metadata candidate words of the target word from the database metadata based on the first metadata type, and will not be repeated here with reference to the above description. Next, the computing device determines the probability value of each second metadata candidate word of the target word based on the probability value of the target word belonging to the second metadata type. For example, the probability value of the target word belonging to the second metadata type is determined as the probability value of each second metadata candidate word of the target word. Alternatively, the computing device determines the probability value of each second metadata candidate word of the target word based on the probability value of the target word belonging to the second metadata type and the word prediction value of the target word in the second metadata type. For example, among the candidate words of the second metadata of the target word, if the candidate word of the second metadata is repeated with the word prediction value of the target word in the second metadata type, when determining the probability value of the repeated candidate word of the second metadata, the sum of the probability value of the target word belonging to the second metadata type and the preset value is determined as the probability value of the repeated candidate word of the second metadata.

[0185] At this point, the probability values ​​of each first metadata candidate word based on the target word, and the probability values ​​of the word prediction value of the target word in each non-metadata type, are sorted to generate a candidate list of the target word. This includes: the computing device sorting the first metadata candidate words, the second metadata candidate words, and the word prediction value of the target word in each non-metadata type based on the probability values ​​of each first metadata candidate word, the probability values ​​of each second metadata candidate word, and the word prediction value of the target word in each non-metadata type to generate a candidate list of the target word.

[0186] In one example, the computing device sorts the first metadata candidate words, the second metadata candidate words, and the predicted word value of the target word in each non-metadata type based on the probability values ​​of each first metadata candidate word, the probability values ​​of each second metadata candidate word, and the probability value of the predicted word value of the target word in each non-metadata type, thus obtaining a first candidate ranking. Simultaneously, it determines the popularity value of each first metadata candidate word and the hot spot value of each second metadata candidate word. In one example, the popularity value of the first metadata candidate word that matches the predicted word value of the target word in the first metadata type is set as the highest popularity value among all first metadata candidate words. Similarly, the popularity value of the second metadata candidate word that matches the predicted word value of the target word in the second metadata type is set as the highest popularity value among all second metadata candidate words. Then, based on the popularity value of each first metadata candidate word, the first metadata candidate words in the first candidate ranking are internally arranged, and based on the popularity value of each second metadata candidate word, the second metadata candidate words in the first candidate ranking are internally arranged, resulting in a candidate list of the target term. At this point, the candidate list includes the first metadata candidate words recalled from the database metadata, as well as the second metadata candidate words under the second metadata type with the highest predicted probability value, thereby improving the accuracy of the candidate list.

[0187] In some embodiments, such as Figure 9 As shown, the query completion method in this embodiment of the application, in addition to using the pop-up prompt completion method described above, also includes a completion method based on a preset keyword and function set, and a completion method based on a preset code template set. In this case, when generating the candidate list of the target term, preset recommended candidate words and the editor's context cached candidate words are also considered. For example, Figure 9 As shown, the computing device first obtains the first query text, the position information of the input cursor in the first query text, and the dialect type used in the first query text. Then, it preprocesses this information, such as performing protocol conversion and extracting prefix characters. Next, it performs completion from three aspects: one is using the pop-up suggestion completion method described in the above embodiment to obtain candidate word element 1 for the target word element; another is completion based on keywords and function sets to obtain pre-recommended candidate words for the target word element; and the third is based on a pre-set code template set to obtain candidate words from the editor's context cache. Then, the candidate words obtained from the above three aspects are deduplicated and rearranged to obtain a candidate list for the target word element. For example, when generating the candidate list, the candidate words generated based on the pop-up suggestion completion method are displayed first, followed by the pre-recommended candidate words and the editor's context cache candidate words in that order.

[0188] As described above, this application's embodiments achieve a mixed sorting of two key prediction results—metadata and word order prediction models—based on lexical type sorting, making them complementary to each other. Simultaneously, the architecture employs a mechanism that prioritizes and mixes candidate words with traditional pre-set recommendations and editor recommendations, supplementing a more relevant candidate set while retaining traditional recommendation capabilities, thus expanding the candidate set within a controllable range.

[0189] In this embodiment, the computing device generates a candidate list of target lexical units based on the above steps. If the computing device is a server, it sends the generated candidate list to the terminal device, which then displays the candidate list. If the computing device is a terminal device, it directly displays the generated candidate list.

[0190] As can be seen from the above, the method in the embodiments of this application, such as Figure 3 As shown, a candidate list of fields can be generated, thereby enabling field completion. For example... Figure 10A As shown, a candidate list of table names can be generated, enabling table name completion. For example... Figure 10B As shown, a candidate list of keywords can be generated to achieve keyword completion. Figure 10C As shown, it can generate a candidate list of functions and perform functions such as function completion.

[0191] The query completion method provided in this application obtains the first query statement being edited by the object and the position information of the input cursor in the first query statement. This first query statement is used to query data from a database. Then, based on the first query statement and the position information of the input cursor, the first word type of the target word appearing after the input cursor is predicted. This first word type belongs to one of N word types, and these N word types include M metadata types (e.g., database name, table name, field name, etc.). If the first word type is a first metadata type, then based on this first metadata type, first metadata candidate words for the target word are retrieved from the database metadata, where the first metadata type is any one of the M metadata types. Furthermore, based on the first metadata candidate words, a candidate list for the target word is generated, and this candidate list is used to complete the target word. Therefore, this application embodiment obtains the query statement being edited by the object and the position of the input cursor, first predicting the word type (i.e., the first word type) of the target word after the input cursor. When the predicted type (i.e., the first word type) is a metadata type, the corresponding metadata candidate words are retrieved from the database metadata. This mechanism of first predicting the type and then selectively recalling metadata ensures that the recommended results not only conform to grammatical norms but also closely match the actual structure of the current database. This avoids the problem of recommended results being disconnected from database objects, as seen in traditional static completion, thereby improving the relevance and accuracy of the completion results. Furthermore, this embodiment, through lexical type prediction, can identify whether the object currently needs editing a table name, field name, or enumeration value, enhancing the understanding of user intent and thus accurately locating the recall scope. In addition, the query statement completion method provided in this embodiment does not rely on specific database products or IDE platforms and can be widely applied to various software tools that support SQL editing, providing a consistent intelligent completion experience for different user groups, demonstrating good versatility and adaptability.

[0192] The above provides an overall overview of the query statement completion method provided in the embodiments of this application. The following section will combine... Figure 11 The query statement completion method of this application embodiment will be further described.

[0193] Figure 11 This is a flowchart illustrating a query statement completion method provided in an embodiment of this application.

[0194] like Figure 11 As shown, the query completion method of this application embodiment includes the following steps: S201. Obtain the first query statement that the object is currently editing, and input the position information of the cursor in the first query statement.

[0195] The first query statement is used to retrieve data from the database.

[0196] The specific implementation process of S201 can be referred to the relevant description of S101 above, and will not be repeated here.

[0197] like Figure 12 As shown, the completion method in this embodiment is performed in two ways: the first way is the metadata retrieval in steps S202 to S203, and the second way is the model prediction in steps S204 to S205. Finally, the dual prediction results are sorted to generate a candidate list of target lexical terms.

[0198] S202. Based on the first query statement and the position information of the input cursor, predict the first word type of the target word that appears after the input cursor.

[0199] Among them, the first lexical type belongs to one of the N lexical types. The N lexical types include M metadata types, where N is a positive integer greater than 1 and M is a positive integer greater than 1 and less than N.

[0200] In some embodiments, based on the position information of the input cursor, the current query segment where the input cursor is located is extracted from the first query statement; a preset placeholder is inserted after the input cursor; the current query segment with the inserted preset placeholder is parsed to predict the word type to which the preset placeholder belongs; and the first word type of the target word is determined based on the word type to which the preset placeholder belongs.

[0201] The specific implementation process of S202 can be referred to the relevant description of S102 above, and will not be repeated here.

[0202] S203. If the first lexical type is the first metadata type, then based on the first metadata type, recall the first metadata candidate word of the target lexical from the database metadata.

[0203] The first metadata type is any one of the M metadata types.

[0204] In some embodiments, based on a first metadata type and a first query statement, first metadata candidate words of the target term are retrieved from database metadata.

[0205] In some embodiments, if the first metadata type is a database name, then the first metadata candidate words include candidate database names. In this case, based on the first metadata type and the first query statement, the first metadata candidate words of the target term are recalled from the database metadata, including: if, based on the first query statement, it is detected that the object has not entered a database name prefix, then each database name included in the database metadata is recalled; if, based on the first query statement, it is detected that the object has entered a database name prefix, then, based on the database name prefix, each database name included in the database metadata with a database name prefix is ​​recalled from each database name included in the database metadata; each database name used by the object in a historical time period and the popularity value of each used database name are obtained; and candidate database names are determined based on the recalled database names, each used database name, and the popularity value of each used database name.

[0206] In some embodiments, if the first metadata type is a table name, then the first metadata candidate words include candidate table names. In this case, based on the first metadata type and the first query statement, the first metadata candidate words of the target term are recalled from the database metadata, including: if, based on the first query statement, it is detected that the object inputs a database name but did not input a table name prefix, recalling each table name under the database name input by the object from the database metadata; if, based on the first query statement, it is detected that the object inputs a database name and a table name prefix, recalling table names with the table name prefix from each table under the database name input by the object from the database metadata; obtaining each table name used by the object in a historical time period, and the popularity value of each used table name; and determining candidate table names based on the recalled table names, the used table names, and the popularity value of each used table name.

[0207] In some embodiments, if the first metadata type is a field, then the first metadata candidate words include candidate fields. In this case, based on the first metadata type and the first query statement, the first metadata candidate words for the target term are retrieved from the database metadata, including: if, based on the first query statement, the object inputs a table name but no field prefix is ​​entered, retrieving each field under the table name entered by the object from the database metadata; if, based on the first query statement, the object inputs a table name and a field prefix is ​​detected, retrieving fields with the field prefix from each field under the table name entered by the object in the database metadata; obtaining each field used by the object in a historical time period, and the popularity value of each used field; and determining candidate fields based on the retrieved fields, the used fields, and the popularity value of each used field.

[0208] In some embodiments, if the first metadata type is an enumeration value, then the first metadata candidate words include candidate enumeration values. In this case, based on the first metadata type and the first query statement, the first metadata candidate words of the target term are recalled from the database metadata, including: if, based on the first query statement, it is detected that an object has an input field, and the input field is an enumeration type, based on the table name and database name to which the input field belongs, a list of enumeration values ​​of the input field are recalled from the database metadata; each enumeration value used by the object in a historical time period, and the popularity value of each used enumeration value; and based on the recalled enumeration value list, each used enumeration value, and the popularity value of each used enumeration value, candidate enumeration values ​​are determined.

[0209] In some embodiments, if the first term type of the target term is not a metadata type but a non-metadata type, then candidate terms of the target term under the non-metadata type are recalled based on the non-metadata type.

[0210] The specific implementation process of S203 can be referred to the relevant description of S103 above, and will not be repeated here.

[0211] S204. The first query statement is segmented into words, and based on the position information of the input cursor, the word units in the segmented first query statement are masked to obtain the masked first query statement.

[0212] The specific implementation process of S204 can be referred to the relevant description of S104-A above, and will not be repeated here.

[0213] S205. Using the trained word order prediction model, perform prediction processing on the first query statement after masking to obtain the probability value of the target word belonging to each of the N word types, and the word prediction value of the target word under each word type.

[0214] In some embodiments, the metadata-type tokens in the masked first query statement are generalized to the corresponding unified tokens to obtain a first token sequence; the token type corresponding to each token in the first token sequence (excluding the mask) is determined to obtain a first token type sequence; the first token sequence and the first token type sequence are processed by the trained word order prediction model to obtain the probability value of the target token belonging to each token type and the token prediction value of the target token under each token type.

[0215] In some embodiments, the trained word order prediction model includes an embedding module and a prediction model. The trained word order prediction model processes the first word sequence and the first word type sequence to obtain the probability value of the target word belonging to each word type and the word prediction value of the target word under each word type. This includes: extracting the embedding information of the first word sequence and the embedding information of the first word type sequence through the embedding module; fusing the embedding information of the first word sequence and the embedding information of the first word type sequence to obtain fused embedding information; and performing prediction processing on the fused embedding information through the prediction module to obtain the probability value of the target word belonging to each word type and the word prediction value of the target word under each word type.

[0216] The specific implementation process of S205 can be referred to the relevant description of S104-B above, and will not be repeated here.

[0217] S206. Based on the first metadata candidate words of the target word, the probability value of the target word belonging to each word type, and the word prediction value of the target word under each word type, generate a candidate list of the target word.

[0218] In some embodiments, from the probability values ​​of the target word belonging to each word type, the probability value of the target word belonging to the first metadata type and the probability value of the target word belonging to each of the NM non-metadata types are read, where the NM non-metadata types are word types other than the M metadata types among the N word types; based on the probability value of the target word belonging to the first metadata type, the probability value of each first metadata candidate word of the target word is determined; for each of the NM non-metadata types, based on the probability value of the target word belonging to the non-metadata type, the probability value of the word prediction value of the target word under the non-metadata type is determined; based on the probability values ​​of each first metadata candidate word and the probability value of the word prediction value of the target word under each non-metadata type, the first metadata candidate words and the word prediction value of the target word under each non-metadata type are sorted to generate a candidate list of the target word.

[0219] In some embodiments, the maximum probability value among the probability values ​​of the target word belonging to M metadata types is read from the probability values ​​of the target word belonging to N word types. If the second metadata type corresponding to the maximum probability value is different from the first metadata type, then the second metadata candidate words of the target word are retrieved from the database metadata based on the second metadata type. Based on the probability value of the target word belonging to the second metadata type, the probability values ​​of each second metadata candidate word of the target word are determined. At this time, based on the probability values ​​of each first metadata candidate word and the probability values ​​of the word prediction values ​​of the target word in each non-metadata type, the first metadata candidate words and the word prediction values ​​of the target word in each non-metadata type are sorted to generate a candidate list of the target word, including: based on the probability values ​​of each first metadata candidate word, the probability values ​​of each second metadata candidate word, and the probability values ​​of the word prediction values ​​of the target word in each non-metadata type, the first metadata candidate words, the second metadata candidate words, and the word prediction values ​​of the target word in each non-metadata type are sorted to generate a candidate list of the target word.

[0220] In some embodiments, based on the probability values ​​of each first metadata candidate word, the probability values ​​of each second metadata candidate word, and the probability values ​​of the predicted word values ​​of the target word in each non-metadata type, the first metadata candidate words, the second metadata candidate words, and the predicted word values ​​of the target word in each non-metadata type are sorted to obtain a first candidate ranking; the popularity value of each first metadata candidate word and the hot spot value of each second metadata candidate word are determined; based on the popularity value of each first metadata candidate word, the first metadata candidate words in the first candidate ranking are internally arranged, and based on the popularity value of each second metadata candidate word, the second metadata candidate words in the first candidate ranking are internally arranged to obtain a candidate list.

[0221] The specific implementation process of S206 can be referred to the relevant description of S104-C above, and will not be repeated here.

[0222] The query completion method provided in this application significantly improves the accuracy and semantic relevance of query completion compared to traditional code completion or single database intelligent suggestion schemes. This is because traditional methods often rely solely on fuzzy matching of the few characters before the cursor, while this scheme, by masking the first query statement and using a trained word order prediction model, can deeply understand the complete syntactic structure and semantic context of the cursor's location. This allows the model to not only predict the word type but also provide the most reasonable word prediction value in that context, avoiding semantic errors caused by relying solely on string matching. Furthermore, this application combines metadata recall (ensuring candidate words physically exist in the database, such as actual table names and column names) and model prediction (ensuring candidate words conform to the logical conventions of natural language and SQL), achieving dual verification of logic and physical data, greatly improving the accuracy of candidate word completion. In addition, this application, through its word order prediction model, can capture long-distance syntactic dependencies, accurately predicting the type of the target word even when the cursor is located deep within complex nesting. The final candidate list is not simply concatenated, but rather a comprehensive weighted ranking based on "type probability (lexical type probability value)" and "content probability (lexical prediction value)," combined with "physical existence (metadata candidate words)." This ensures that table names, column names, or keywords that best fit the current context are ranked at the top of the candidate list, reducing the time users spend flipping through pages and providing a more intelligent and richer candidate list ranking.

[0223] The preceding text uses a computing device as an example to describe the specific process of the embodiments of this application. The following text uses a system consisting of an editor and a server as an example to further describe the query statement completion process of the embodiments of this application.

[0224] Figure 13 This is a flowchart illustrating a query statement completion method provided in an embodiment of this application.

[0225] like Figure 13 As shown, the query statement completion method of this application embodiment includes the following steps: S301. When the editor detects that the first query statement for object editing has been sent, it sends a completion request to the server.

[0226] The completion request includes the first query prediction of the object being edited, and the position information of the input cursor in the first query statement.

[0227] In some embodiments, such as Figure 14 As shown, the application in this embodiment adopts a three-layer architecture, consisting of three components: an editor, a server (e.g., an LSP server), and a pop-up suggestion algorithm. The pop-up suggestion algorithm is deployed on the server. Database metadata serves as an external dependency, allowing the pop-up algorithm to access and use it as needed. The pop-up suggestion algorithm here can be understood as the specific implementation process of the pop-up suggestion completion involved in this embodiment, that is, the core part of the query statement completion method provided in this embodiment.

[0228] S302. The server parses the supplementary request and obtains the first query statement that the object is editing, as well as the position information of the input cursor in the first query statement.

[0229] In some embodiments, the editor and the server are connected via a long connection. The server parses the supplementary requests sent by the editor to obtain the first query statement that the object is editing, as well as the position information of the input cursor in the first query statement.

[0230] S303. Based on the first query statement and the position information of the input cursor, the server predicts the first word type of the target word that appears after the input cursor.

[0231] The specific implementation process of S303 can be referred to the relevant description of S102 above, and will not be repeated here.

[0232] S304. If the first lexical type is the first metadata type, then based on the first metadata type, recall the first metadata candidate word of the target lexical from the database metadata.

[0233] The first metadata type is any one of the M metadata types.

[0234] The specific implementation process of S304 can be referred to the relevant description of S103 above, and will not be repeated here.

[0235] S305. The server performs word segmentation on the first query statement and, based on the position information of the input cursor, performs masking on the word units in the segmented first query statement to obtain the masked first query statement.

[0236] The specific implementation process of S305 can be referred to the relevant description of S104-A above, and will not be repeated here.

[0237] S306. The server uses the trained word order prediction model to predict the first query statement after masking, and obtains the probability value of the target word belonging to each of the N word types, as well as the word prediction value of the target word under each word type.

[0238] The specific implementation process of S306 can be referred to the relevant description of S104-B above, and will not be repeated here.

[0239] S307. The server generates a candidate list of target words based on the first metadata candidate words of the target word, the probability value of the target word belonging to each word type, and the word prediction value of the target word under each word type.

[0240] The specific implementation process of S307 can be referred to the relevant description of S104-C above, and will not be repeated here.

[0241] S308. The server sends the generated candidate list to the editor.

[0242] S309. The editor displays the candidate list.

[0243] For example, the editor displays the candidate list near the input cursor so that the object can select the desired candidate word from the list to complete the target word, thereby improving the accuracy and efficiency of the target word completion.

[0244] The query completion method provided in this application involves collaboration between an editor and a server. The editor sends completion requests to the server in real-time based on object editing operations. The server generates a candidate list of target terms by integrating metadata retrieval based on grammar rules with a word order prediction model based on deep learning, and sends this candidate list to the editor. The editor then displays this candidate list, significantly improving the accuracy and semantic relevance of query completion. The above text combined Figures 2 to 13 The method embodiments of this application are described in detail below, in conjunction with... Figure 15 The following describes in detail the device embodiments of this application.

[0245] Figure 15 This is a schematic block diagram of a query statement completion device provided in an embodiment of this application.

[0246] like Figure 15 As shown, the query completion device 10 includes: The acquisition unit 11 is used to acquire the first query statement that the object is editing, and the position information of the input cursor in the first query statement, wherein the first query statement is used to query data from the database; The type prediction unit 12 is used to predict the first word type of the target word that appears after the input cursor based on the first query statement and the position information of the input cursor. The first word type belongs to one of N word types. The N word types include M metadata types. N is a positive integer greater than 1 and M is a positive integer greater than 1 and less than N. The recall unit 13 is used to recall the first metadata candidate word of the target word from the database metadata based on the first metadata type when the first word type is the first metadata type. The first metadata type is any one of the M metadata types. The generation unit 14 is used to generate a candidate list of the target word based on the first metadata candidate words, and the candidate list is used to complete the target word.

[0247] In some embodiments, the type prediction unit 12 is specifically used to: extract the current query segment where the input cursor is located from the first query statement based on the position information of the input cursor; insert a preset placeholder after the input cursor; perform syntactic parsing on the current query segment with the inserted preset placeholder to predict the word type to which the preset placeholder belongs; and determine the first word type of the target word based on the word type to which the preset placeholder belongs.

[0248] In some embodiments, the recall unit 13 is specifically used to recall the first metadata candidate word of the target word from the database metadata based on the first metadata type and the first query statement.

[0249] In some embodiments, if the first metadata type is a database name, then the first metadata candidate words include candidate database names. The recall unit 13 is specifically configured to: recall each database name included in the database metadata when it is detected that the object has not entered a database name prefix based on the first query statement; recall database names whose prefix is ​​the database name prefix from each database name included in the database metadata based on the database name prefix when it is detected that the object has entered a database name prefix based on the first query statement; obtain each database name used by the object in a historical time period, and the popularity value of each used database name; and determine the candidate database name based on the recalled database names, the used database names, and the popularity value of each used database name.

[0250] In some embodiments, if the first metadata type is a table name, then the first metadata candidate words include candidate table names. The recall unit 13 is specifically configured to: when, based on the first query statement, it is detected that the object inputs a database name but does not input a table name prefix, recall each table name under the database name input by the object from the database metadata; when, based on the first query statement, it is detected that the object inputs both a database name and a table name prefix, recall each table name with the prefix "table name prefix" from each table under the database name input by the object in the database metadata; obtain each table name used by the object in a historical time period, and the popularity value of each used table name; and determine the candidate table name based on the recalled table names, the used table names, and the popularity value of each used table name.

[0251] In some embodiments, if the first metadata type is a field, then the first metadata candidate words include candidate fields. The recall unit 13 is specifically configured to: when, based on the first query statement, it is detected that the object has entered a table name but has not entered a field prefix, recall each field under the table name entered by the object from the database metadata; when, based on the first query statement, it is detected that the object has entered a table name and a field prefix, recall fields with the field prefix from each field under the table name entered by the object in the database metadata; obtain each field used by the object in a historical time period, and the popularity value of each used field; and determine the candidate fields based on the recalled fields, the used fields, and the popularity value of each used field.

[0252] In some embodiments, if the first metadata type is an enumeration value, then the first metadata candidate terms include candidate enumeration values. The recall unit 13 is specifically configured to, based on the first query statement, detect that the object has an input field, and the input field is an enumeration type, recall the enumeration value list of the input field from the database metadata based on the table name and database name to which the input field belongs; obtain each enumeration value used by the object in a historical time period, and the popularity value of each used enumeration value; and determine the candidate enumeration value based on the recalled enumeration value list, each used enumeration value, and the popularity value of each used enumeration value.

[0253] In some embodiments, the generation unit 14 is specifically used to segment the first query statement into words, and based on the position information of the input cursor, to mask the word elements in the segmented first query statement to obtain a masked first query statement; to perform prediction processing on the masked first query statement through a trained word order prediction model to obtain the probability value of the target word element belonging to each of the N word element types, and the word element prediction value of the target word element under each word element type; and to generate a candidate list of the target word element based on the first metadata candidate words of the target word element, the probability value of the target word element belonging to each word element type, and the word element prediction value of the target word element under each word element type.

[0254] In some embodiments, the generation unit 14 is specifically used to generalize the metadata type tokens in the first query statement after the mask to the corresponding unified tokens to obtain a first token sequence; determine the token type corresponding to each token in the first token sequence except the mask to obtain a first token type sequence; and process the first token sequence and the first token type sequence through the trained word order prediction model to obtain the probability value of the target token belonging to each token type and the token prediction value of the target token under each token type.

[0255] In some embodiments, the trained word order prediction model includes an embedding module and a prediction model. The generation unit 14 is specifically used to extract the embedding information of the first word sequence and the embedding information of the first word type sequence through the embedding module; fuse the embedding information of the first word sequence and the embedding information of the first word type sequence to obtain fused embedding information; and perform prediction processing on the fused embedding information through the prediction module to obtain the probability value of the target word belonging to each word type and the word prediction value of the target word under each word type.

[0256] In some embodiments, the generation unit 14 is specifically configured to: read from the probability values ​​of the target word belonging to the first metadata type and the probability values ​​of the target word belonging to each of the NM non-metadata types, where the NM non-metadata types are word types other than the M metadata types among the N word types; determine the probability values ​​of each first metadata candidate word of the target word based on the probability values ​​of the target word belonging to the first metadata type; for each of the NM non-metadata types, determine the probability value of the word prediction value of the target word under the non-metadata type based on the probability values ​​of the target word belonging to the non-metadata type; and sort the first metadata candidate words and the word prediction values ​​of the target word under each non-metadata type based on the probability values ​​of each first metadata candidate word and the probability values ​​of the word prediction value of the target word under each non-metadata type to generate a candidate list of the target word.

[0257] In some embodiments, the generation unit 14 is further configured to: read the maximum probability value among the probability values ​​of the target word belonging to the M metadata types from the probability values ​​of the target word belonging to the N word types; if the second metadata type corresponding to the maximum probability value is different from the first metadata type, then recall the second metadata candidate word of the target word from the database metadata based on the second metadata type; determine the probability value of each second metadata candidate word of the target word based on the probability value of the target word belonging to the second metadata type; and sort each first metadata candidate word, each second metadata candidate word, and the word prediction value of the target word in each non-metadata type based on the probability values ​​of each first metadata candidate word, the probability values ​​of each second metadata candidate word, and the probability value of the word prediction value of the target word in each non-metadata type to generate a candidate list of the target word.

[0258] In some embodiments, the generation unit 14 is specifically configured to sort the first metadata candidate words, the second metadata candidate words, and the lexical prediction values ​​of the target lexical in each non-metadata type based on the probability values ​​of each first metadata candidate word, the probability values ​​of each second metadata candidate word, and the probability values ​​of the lexical prediction values ​​of the target lexical in each non-metadata type, to obtain a first candidate sort; determine the popularity value of each first metadata candidate word and the hot spot value of each second metadata candidate word; internally arrange each first metadata candidate word in the first candidate sort based on the popularity value of each first metadata candidate word, and internally arrange each second metadata candidate word in the first candidate sort based on the popularity value of each second metadata candidate word, to obtain the candidate list.

[0259] In some embodiments, the generation unit 14 is specifically configured to set the popularity value of the first metadata candidate word that is consistent with the word prediction value of the target word under the first metadata type as the highest popularity value among the first metadata candidate words; and to set the popularity value of the second metadata candidate word that is consistent with the word prediction value of the target word under the second metadata type as the highest popularity value among the second metadata candidate words.

[0260] In some embodiments, the process of training the word order prediction model includes: acquiring training samples, the training samples including training query statements; performing word segmentation on the training query statements, and masking the word units in the segmented training query statements based on random positions to obtain masked training query statements; performing prediction processing on the masked training query statements using the word order prediction model to obtain the probability value of the word unit at the random position belonging to each word unit type, and the word unit prediction value of the word unit at the random position under each word unit type; determining the model loss value based on the probability value of the word unit at the random position belonging to each word unit type, and the word unit prediction value of the word unit at the random position under each word unit type, and training the word order prediction model based on the model loss value to obtain the trained word order prediction model.

[0261] In some embodiments, the step of performing prediction processing on the masked training query statement using the word order prediction model to obtain the probability value of the word element at the random position belonging to each word element type, and the word element prediction value of the word element at the random position under each word element type, includes: generalizing the word elements belonging to the metadata type in the masked training query statement to the corresponding unified word elements to obtain a second word element sequence; determining the word element type corresponding to each word element in the second word element sequence excluding the mask to obtain a second word element type sequence; and performing prediction processing on the second word element sequence and the second word element type sequence using the word order prediction model to obtain the probability value of the word element at the random position belonging to each word element type, and the word element prediction value of the word element at the random position under each word element type.

[0262] In some embodiments, determining the model loss value based on the probability value of the word at the random position belonging to each word type and the word prediction value of the word at the random position under each word type includes: determining the target word type with the highest probability value from the probability values ​​of the word at the random position belonging to each word type; determining the word type prediction loss value based on the probability value of the word at the random position belonging to the target word type and the true word type of the word at the random position in the training query statement; determining the word prediction loss value based on the word prediction value of the word at the random position under the target word type and the true word at the random position in the training query statement; and determining the model loss value based on the word type prediction loss value and the word prediction loss value.

[0263] It should be understood that the device embodiments and method embodiments can correspond to each other, and similar descriptions can be referred to the method embodiments. To avoid repetition, further details will not be provided here. Specifically, Figure 15 The apparatus shown can perform the embodiments of the above-described method, and the foregoing and other operations and / or functions of each module in the apparatus are respectively for implementing the above-described system-side method embodiments, which will not be described in detail here for the sake of brevity.

[0264] The apparatus of this application embodiment has been described above from the perspective of functional modules in conjunction with the accompanying drawings. It should be understood that this functional module can be implemented in hardware, in software instructions, or in a combination of hardware and software modules. Specifically, the steps of the method embodiments in this application can be completed by integrated logic circuits in the processor's hardware and / or by software instructions. The steps of the method disclosed in this application embodiment can be directly embodied as being executed by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. Optionally, the software module can reside in a mature storage medium in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. This storage medium is located in memory, and the processor reads information from the memory and, in conjunction with its hardware, completes the steps in the above method embodiments.

[0265] Figure 16 This is a schematic block diagram of a computing device provided in an embodiment of this application. The computing device may be the terminal device or server described above.

[0266] like Figure 16 As shown, the computing device 40 may include: The system includes a memory 41 and a processor 42. The memory 41 stores a computer program 43 and transfers the program code 43 to the processor 42. In other words, the processor 42 can retrieve and run the computer program 43 from the memory 41 to implement the methods described in the embodiments of this application.

[0267] For example, the processor 42 can be used to execute the steps in the method 200 described above according to the instructions in the computer program 43.

[0268] In some embodiments of this application, the processor 42 may include, but is not limited to: General-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.

[0269] In some embodiments of this application, the memory 41 includes, but is not limited to: Volatile memory and / or non-volatile memory. Non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDR SDRAM), Enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), and Direct Rambus RAM (DR RAM).

[0270] In some embodiments of this application, the computer program 43 may be divided into one or more modules, which are stored in the memory 41 and executed by the processor 42 to complete the page recording method provided in this application. The one or more modules may be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of the computer program 43 in the computing device.

[0271] like Figure 16 As shown, the computing device 40 may further include: Transceiver 44, which can be connected to processor 42 or memory 41.

[0272] The processor 42 can control the transceiver 44 to communicate with other devices; specifically, it can send information or data to other devices or receive information or data sent by other devices. The transceiver 44 may include a transmitter and a receiver. The transceiver 44 may further include antennas, and the number of antennas may be one or more.

[0273] It should be understood that the various components in the computing device 40 are connected through a bus system, which includes a data bus, a power bus, a control bus, and a status signal bus.

[0274] According to one aspect of this application, a computer storage medium is provided that stores a computer program thereon, which, when executed by a computer, enables the computer to perform the methods of the above-described method embodiments. Alternatively, embodiments of this application also provide a computer program product containing instructions that, when executed by a computer, cause the computer to perform the methods of the above-described method embodiments.

[0275] According to another aspect of this application, a computer program product or computer program is provided, comprising computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the method described in the above-described method embodiments.

[0276] In other words, when implemented using software, it can be implemented wholly or partially in the form of a computer program product. This computer program product includes one or more computer instructions. When these computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., digital video disc (DVD)), or a semiconductor medium (e.g., solid-state disk (SSD)).

[0277] Those skilled in the art will recognize that the modules and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0278] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or modules may be electrical, mechanical, or other forms.

[0279] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. For example, the functional modules in the various embodiments of this application may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.

[0280] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.< / column> < / column> , all kinds of fields are generalized into a unified token <COLUMN>. For tokens such as keywords and functions that can be enumerated, their original semantics are retained. Then, the token type corresponding to each token except the mask in the first token sequence is determined to obtain the first token type sequence. For example, for each token except the mask in the first token sequence, the training device determines which of the N token types this token belongs to, and then obtains the first token type sequence corresponding to the first token sequence. These N token types include: database name, table name, field, enumerated value, keyword, function, etc. In some embodiments, the first query statement after word segmentation can also be generalized first and then masked. Then, through the trained word order prediction model, the first token sequence and the first token type sequence are processed to predict the probability value of the target token belonging to each of the N token types, and the token prediction value of the target token under each token type. In some embodiments, as shown, the trained word order prediction model includes an embedding module and a prediction model. In this way, the computing device inputs the first token sequence and the first token type sequence into the embedding module, and the embedding module extracts the embedding information of the first token sequence, for example, maps the tokens in the first token sequence to dense vectors. Similarly, the embedding module extracts the embedding information of the first token type sequence, for example, maps each token type (such as KEYWORD, COLUMN) in the first token type sequence to another vector. Then, the embedding information of the first token sequence and the embedding information of the first token type sequence are fused to obtain fused embedding information. Optionally, when encoding the above features, position information can also be added to enable the model to perceive the sequence order. For example, the position information of the first token sequence is extracted, and the position information of the first token type sequence is extracted. Then, the embedding information of the first token sequence and the position information, as well as the embedding information of the first token type sequence and the position information, are fused to obtain fused embedding information. The above feature fusion methods can be concatenation, addition, etc. Then, as shown, the computing device inputs the fused embedding information into the prediction module, and through this prediction module, the fused embedding information is predicted and processed to obtain the probability value of the target token belonging to each token type, and the token prediction value of the target token under each token type. In some embodiments, in the online deployment of the word order prediction model, an offline pre-brushing cache mechanism is adopted. The offline pre-brushing cache mechanism is a key technology that balances real-time performance and computational cost. Its core idea is: pre-compute and store the prediction results corresponding to common SQL contexts. When a user request hits the cache, it is directly returned, avoiding real-time model inference, thereby greatly reducing the response latency and server load. For example, the most frequently occurring generalized context patterns are statistically counted from historical SQL logs as pre-brushing candidates. The trained word order prediction model is used to perform batch inference on these patterns to generate prediction results.The prediction results are stored in a high-speed cache (such as Redis or Memcached), with the key being the generalized sequence and the value being the serialized prediction result. As new SQL queries emerge, the pattern distribution may change, requiring periodic (e.g., daily) re-statistical updates and cache refresh. Thus, when the first query arrives, a cache key is first generated based on the first query, and then the cache is queried based on that key. If the cache is hit, the prediction result in the cache is directly returned. If not, an online word order prediction model is invoked for real-time inference to obtain the result. Optionally, this result can be asynchronously backfilled into the cache (with an appropriate expiration time set) so that subsequent identical requests can hit it. In this embodiment, after obtaining the probability value of the target word belonging to each word type and the word prediction value of the target word under each word type, the computing device executes the steps of S104-C above, generating a candidate list of the target word based on the first metadata candidate words of the target word, the probability value of the target word belonging to each word type, and the word prediction value of the target word under each word type. This application embodiment does not limit the specific method by which the computing device generates a candidate list of target words based on the first metadata candidate words of the target word, the probability value of the target word belonging to each word type, and the word prediction value of the target word under each word type. In some embodiments, as described above, the first metadata candidate words of the target word are the metadata candidate words of the target word recalled from the database metadata based on the first metadata type when the computing device determines that the first word type of the target word is the first metadata type. Based on this, the computing device can arrange the first metadata candidate words of the target word at the top of the candidate list. At the same time, it obtains one or several word types with the highest probability value among the probability values ​​of the target word belonging to each word type (it should be noted that the first metadata type is not included in the one or several word types with the highest probability value), and then adds the word prediction value of the target word under the one or several word types with the highest probability value to the candidate list according to the probability value, thus obtaining the candidate list of the target word.In some embodiments, S104-C includes the following steps S104-C1 to S104-C4: S104-C1: From the probability values ​​of the target word belonging to each word type, read the probability value of the target word belonging to a first metadata type and the probability value of the target word belonging to each of the NM non-metadata types, where the NM non-metadata types are word types other than the M metadata types among the N word types; S104-C2: Based on the probability values ​​of the target word belonging to the first metadata type, determine each first... The probability values ​​of metadata candidate words; S104-C3, for each of the NM non-metadata types, based on the probability value of the target word belonging to the non-metadata type, determine the probability value of the word prediction value of the target word under the non-metadata type; S104-C4, based on the probability values ​​of each first metadata candidate word and the probability value of the word prediction value of the target word under each non-metadata type, sort the first metadata candidate words and the word prediction value of the target word under each non-metadata type to generate a candidate list of the target word. In this implementation, the computing device reads the probability value of the target word belonging to the first metadata type from the probability values ​​of the target word belonging to each word type. Then, based on the probability value of the target word belonging to the first metadata type, it determines the probability values ​​of each first metadata candidate word of the target word. In one possible implementation, the probability value of the target word belonging to the first metadata type is determined as the probability value of each first metadata candidate word of the target word. That is, the probability values ​​of all candidate words for the first metadata of the target word are consistent, all being the probability values ​​of the target word belonging to the first metadata type. In one possible implementation, the computing device determines the probability values ​​of each candidate word for the first metadata of the target word based on the probability value of the target word belonging to the first metadata type and the word prediction value of the target word in the first metadata type. For example, the computing device, based on the candidate words for the first metadata of the target word determined in step S103 above, assumes to be a, b, c, and d. Assume that after the above steps, the probability value of the target word belonging to the first metadata type is determined to be g1, and the word prediction value of the target word in the first metadata type is a and c. At this time, the probability values ​​of each candidate word for the first metadata of the target word a, b, c, and d are respectively: g1+g0, g1, g1+g0, g1. In other words, for each candidate word of the first metadata element of the target word, if the candidate word of the first metadata element is the same as the word prediction value of the target word element in the first metadata type, when determining the probability value of the repeated candidate word of the first metadata element, the sum of the probability value of the target word element belonging to the first metadata type and a preset value is determined as the probability value of the repeated candidate word of the first metadata element. The preset value is a positive number greater than 0.Simultaneously, the computing device reads the probability value of the target word belonging to each of the NM non-metadata types from the probability value of the target word belonging to each word type. These NM non-metadata types are word types other than the M metadata types out of the N word types. For example, these NM non-metadata types include keyword types, function types, etc. For each of these NM non-metadata types, the computing device determines the probability value of the word prediction value of the target word under that non-metadata type based on the probability value of the target word belonging to that non-metadata type. For example, the computing device determines the probability value of the target word belonging to that non-metadata type as the probability value of the word prediction value of the target word under that non-metadata type. For example, the computing device determines the probability value of the target word belonging to the keyword type as the probability value of the word prediction value (i.e., each keyword) of the target word under that keyword type. Next, the computing device sorts the first metadata candidate words and the predicted word values ​​of the target word in each non-metadata type based on the probability values ​​of each first metadata candidate word and the predicted word values ​​of the target word in each non-metadata type, generating a candidate list for the target word. For example, suppose the first query is: SELECT u.name, o.FROM users u JOIN orders o ON u.id = o.user_id WHERE o., where the input cursor is after WHERE o. Assume that, based on the recall strategies S102 and S103 above, the computing device determines the first word type of the target word as a field (COLUMN), and the first metadata candidate words (i.e., candidate fields) recalled from the database metadata are ['amount', 'status', 'id', 'user_id', 'product_id'], and the popularity values ​​of these candidate fields are [1.2, 1.0, 0.8, 0.8, 0.8]. Suppose that the computing device uses a trained word order prediction model to predict the probability that the target word belongs to one of N word types, which are: belonging to field.

Claims

1. A query statement completion method, characterized in that, include: Obtain the first query statement that the object is currently editing, as well as the position information of the input cursor in the first query statement, which is used to query data from the database; Based on the first query statement and the position information of the input cursor, predict the first word type of the target word that appears after the input cursor. The first word type belongs to one of N word types. The N word types include M metadata types, where N is a positive integer greater than 1 and M is a positive integer greater than 1 and less than N. If the first lexical type is the first metadata type, then based on the first metadata type, the first metadata candidate word of the target lexical is recalled from the database metadata, where the first metadata type is any one of the M metadata types; Based on the first metadata candidate words, a candidate list of the target word is generated, and the candidate list is used to complete the target word.

2. The method according to claim 1, characterized in that, The step of predicting the first word type of the target word that appears after the input cursor based on the first query statement and the position information of the input cursor includes: Based on the position information of the input cursor, the current query segment where the input cursor is located is extracted from the first query statement; Insert a preset placeholder after the input cursor; Perform syntax parsing on the current query segment with the preset placeholder inserted, and predict the word type to which the preset placeholder belongs; Based on the word type to which the preset placeholder belongs, the first word type of the target word is determined.

3. The method according to claim 1, characterized in that, The step of recalling first metadata candidate words for the target lexical unit from database metadata based on the first metadata type includes: Based on the first metadata type and the first query statement, the first metadata candidate word of the target word is retrieved from the database metadata.

4. The method according to claim 3, characterized in that, If the first metadata type is a database name, then the first metadata candidate words include candidate database names. The step of retrieving the first metadata candidate words for the target term from the database metadata based on the first metadata type and the first query statement includes: If, based on the first query statement, it is detected that the object has not entered a database name prefix, then the database names included in the database metadata are recalled; If the object input database name prefix is ​​detected based on the first query statement, then based on the database name prefix, the database names with the database name prefix are recalled from each database name included in the database metadata; Obtain the names of each database used by the object during a historical time period, and the popularity value of each of the database names used; The candidate database names are determined based on the recalled database names, the used database names, and the popularity values ​​of the used database names.

5. The method according to claim 3, characterized in that, If the first metadata type is a table name, then the first metadata candidate words include candidate table names. The step of retrieving the first metadata candidate words for the target term from the database metadata based on the first metadata type and the first query statement includes: If, based on the first query statement, it is detected that the object has entered a database name but has not entered a table name prefix, the table names under the database name entered by the object are retrieved from the database metadata. If, based on the first query statement, the object inputs a database name and a table name prefix, then, from the database metadata, retrieve table names whose prefix is ​​the table name prefix from each table under the database name input by the object. Obtain the table names used by the object during the historical time period, and the popularity value of each of the table names used; The candidate table names are determined based on the recalled table names, the used table names, and the popularity values ​​of the used table names.

6. The method according to claim 3, characterized in that, If the first metadata type is a field, then the first metadata candidate words include candidate fields. The step of retrieving the first metadata candidate words for the target term from the database metadata based on the first metadata type and the first query statement includes: If, based on the first query statement, it is detected that the object has entered a table name but has not entered a field prefix, the fields under the table name entered by the object are retrieved from the database metadata. If, based on the first query statement, the object input table name and field prefix are detected, the fields whose prefix is ​​the field prefix are retrieved from each field under the table name input by the object in the database metadata; Obtain the fields used by the object during the historical time period, and the popularity value of each of the used fields; The candidate fields are determined based on the recalled fields, the used fields, and the popularity values ​​of the used fields.

7. The method according to claim 3, characterized in that, If the first metadata type is an enumerated value, then the first metadata candidate word includes candidate enumerated values. The step of recalling the first metadata candidate word for the target term from the database metadata based on the first metadata type and the first query statement includes: If, based on the first query statement, it is detected that the object has an input field and the input field is an enumeration type, the enumeration value list of the input field is retrieved from the database metadata based on the table name and database name to which the input field belongs. Obtain the enumeration values ​​used by the object during the historical time period, as well as the popularity value of each of the enumeration values ​​used. The candidate enumeration values ​​are determined based on the recalled list of enumeration values, each of the used enumeration values, and the popularity value of each of the used enumeration values.

8. The method according to any one of claims 1-7, characterized in that, The step of generating a candidate list of target lexical units based on the first metadata candidate words includes: The first query statement is segmented into words, and based on the position information of the input cursor, the word units in the segmented first query statement are masked to obtain the masked first query statement. The trained word order prediction model is used to predict the first query statement after the mask to obtain the probability value of the target word belonging to each of the N word types, and the word prediction value of the target word under each word type. Based on the first metadata candidate words of the target word, the probability value of the target word belonging to each word type, and the word prediction value of the target word under each word type, a candidate list of the target word is generated.

9. The method according to claim 8, characterized in that, The step of using the trained word order prediction model to predict the first query statement after the masking, and obtaining the probability value of the target word belonging to each of the N word types, and the word prediction value of the target word under each word type, includes: The metadata-type tokens in the first query statement after the mask are generalized to the corresponding unified tokens to obtain the first token sequence. Determine the lexical type corresponding to each lexical in the first lexical sequence except for the mask, to obtain the first lexical type sequence; The trained word order prediction model is used to process the first word sequence and the first word type sequence to obtain the probability value of the target word belonging to each word type and the word prediction value of the target word under each word type.

10. The method according to claim 9, characterized in that, The trained word order prediction model includes an embedding module and a prediction model. The trained word order prediction model processes the first word sequence and the first word type sequence to obtain the probability value of the target word belonging to each word type, and the word prediction value of the target word under each word type, including: The embedding module extracts the embedding information of the first word sequence and the embedding information of the first word type sequence, respectively. The embedding information of the first word sequence and the embedding information of the first word type sequence are fused to obtain fused embedding information; The prediction module performs prediction processing on the fused embedded information to obtain the probability value of the target word belonging to each word type, and the word prediction value of the target word under each word type.

11. The method according to claim 8, characterized in that, The process of generating a candidate list for the target word based on the first metadata candidate words of the target word, the probability value of the target word belonging to each word type, and the word prediction value of the target word under each word type includes: From the probability values ​​of the target word belonging to each word type, read the probability value of the target word belonging to the first metadata type, and the probability value of the target word belonging to each of the NM non-metadata types, where the NM non-metadata types are word types other than the M metadata types among the N word types; Based on the probability value of the target word belonging to the first metadata type, the probability value of each first metadata candidate word of the target word is determined; For each of the NM non-metadata types, based on the probability value of the target word belonging to the non-metadata type, determine the probability value of the word prediction value of the target word under the non-metadata type; Based on the probability values ​​of each of the first metadata candidate words and the probability values ​​of the predicted word values ​​of the target word in each non-metadata type, the predicted word values ​​of each of the first metadata candidate words and the target word in each non-metadata type are sorted to generate a candidate list of the target word.

12. The method according to claim 11, characterized in that, The method further includes: From the probability values ​​of the target word belonging to the N word types, read the maximum probability value among the probability values ​​of the target word belonging to the M metadata types; If the second metadata type corresponding to the maximum probability value is different from the first metadata type, then based on the second metadata type, the second metadata candidate word of the target word is recalled from the database metadata; Based on the probability value of the target word belonging to the second metadata type, the probability value of each second metadata candidate word of the target word is determined; The method involves sorting the lexical prediction values ​​of each first metadata candidate word and the target word in each non-metadata type based on their probability values ​​and the probability values ​​of their predicted values ​​in each non-metadata type, thereby generating a candidate list for the target word, including: Based on the probability values ​​of each first metadata candidate word, the probability values ​​of each second metadata candidate word, and the probability values ​​of the predicted word value of the target word in each non-metadata type, the first metadata candidate words, the second metadata candidate words, and the predicted word value of the target word in each non-metadata type are sorted to generate a candidate list of the target word.

13. The method according to claim 12, characterized in that, The method involves sorting the first metadata candidate words, the second metadata candidate words, and the predicted word value of the target word in each non-metadata type based on the probability values ​​of each first metadata candidate word, the probability values ​​of each second metadata candidate word, and the predicted word value of the target word in each non-metadata type, to generate a candidate list of the target word, including: Based on the probability values ​​of each first metadata candidate word, the probability values ​​of each second metadata candidate word, and the probability values ​​of the predicted word value of the target word in each non-metadata type, the first metadata candidate words, the second metadata candidate words, and the predicted word value of the target word in each non-metadata type are sorted to obtain the first candidate sort. Determine the popularity value of each first metadata candidate word and the hot spot value of each second metadata candidate word; Based on the popularity value of each first metadata candidate word, the first metadata candidate words in the first candidate sort are internally arranged, and based on the popularity value of each second metadata candidate word, the second metadata candidate words in the first candidate sort are internally arranged to obtain the candidate list.

14. The method according to claim 13, characterized in that, Determining the popularity value of each first metadata candidate word and the hot spot value of each second metadata candidate word includes: The popularity value of the first metadata candidate word that is consistent with the word prediction value of the target word under the first metadata type is set as the highest popularity value among the first metadata candidate words. The popularity value of the second metadata candidate word that matches the word prediction value of the target word under the second metadata type is set as the highest popularity value among the second metadata candidate words.

15. The method according to claim 8, characterized in that, The process of training the word order prediction model includes: Obtain training samples, which include training query statements; The training query statement is segmented into words, and the words in the segmented training query statement are masked based on random positions to obtain the masked training query statement. The word order prediction model is used to predict the training query statement after the mask to obtain the probability value of the word at the random position belonging to each word type, and the word prediction value of the word at the random position under each word type. Based on the probability value of the word at the random position belonging to each word type, and the word prediction value of the word at the random position under each word type, the model loss value is determined, and the word order prediction model is trained based on the model loss value to obtain the trained word order prediction model.

16. The method according to claim 15, characterized in that, The step of using the word order prediction model to predict the masked training query statement to obtain the probability value of the word at the random position belonging to each word type, and the word prediction value of the word at the random position under each word type, includes: The metadata-type tokens in the masked training query statement are generalized to the corresponding unified tokens to obtain the second token sequence. Determine the lexical type corresponding to each lexical in the second lexical sequence except for the mask, to obtain the second lexical type sequence; The word order prediction model is used to predict the second word sequence and the second word type sequence to obtain the probability value of the word at the random position belonging to each word type, and the word prediction value of the word at the random position under each word type.

17. The method according to claim 15, characterized in that, The method of determining the model loss value based on the probability value of the word at the random position belonging to each word type and the word prediction value of the word at the random position under each word type includes: From the probability values ​​of the word elements at the random positions belonging to each word element type, determine the target word element type with the highest probability value; Based on the probability value of the word at the random position belonging to the target word type, and the true word type of the word at the random position in the training query statement, the word type prediction loss value is determined. Based on the predicted word value of the word at the random position under the target word type, and the real word at the random position in the training query statement, the word prediction loss value is determined. The model loss value is determined based on the word type prediction loss value and the word prediction loss value.

18. A query statement completion device, characterized in that, The device includes: The acquisition unit is used to acquire the first query statement that the object is editing, and the position information of the input cursor in the first query statement, which is used to query data from the database; The type prediction unit is used to predict the first word type of the target word that appears after the input cursor based on the first query statement and the position information of the input cursor. The first word type belongs to one of N word types. The N word types include M metadata types, where N is a positive integer greater than 1 and M is a positive integer greater than 1 and less than N. The recall unit is used to recall the first metadata candidate word of the target word from the database metadata based on the first metadata type when the first word type is the first metadata type. The first metadata type is any one of the M metadata types. The generation unit is configured to generate a candidate list of the target lexical based on the first metadata candidate words, the candidate list being used to complete the target lexical.

19. A computing device, characterized in that, Including processor and memory; The memory is used to store computer programs; The processor is configured to execute the computer program to implement the method as described in any one of claims 1 to 17.

20. A computer-readable storage medium, characterized in that, Used to store computer programs; The computer program causes the computer to perform the method as described in any one of claims 1 to 17.