Conversion method, device, equipment, medium and product
By obtaining SQL statements in the source database system, searching the conversion rule database and database information, generating prompt words and using the target model to process it, the compatibility problems caused by the differences in SQL dialects between different database systems are solved, and automated SQL dialect conversion, efficient database migration and cross-platform query are realized.
Patent Information
- Application Number
- CN202510246258.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-03
- Publication Date
- 2025-06-17
AI Technical Summary
Due to the differences in SQL dialects between different database systems, there are compatibility problems, which makes it difficult to realize automatic conversion of SQL dialects in scenarios such as database migration, cross-platform query and distributed data management.
By obtaining SQL statements in the source database system, searching the matching rules in the pre-constructed transformation rule database and relevant information in the database, generating prompt words, and using the target model to process the prompt words to generate equivalent SQL statements under the target database system.
It realizes automated SQL dialect conversion, reduces the need to manually write conversion rules, reduces development difficulty and workload, and improves the efficiency of database migration, cross-platform query and distributed data management.
Smart Images

Figure CN120162377A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of big data technology, and in particular, to a conversion method, device, equipment, medium, and product. Background Art
[0002] With the continuous development of technology, there are more and more database systems with excellent performance, enabling these database systems to provide better database services for users, such as data storage and data query services.
[0003] In addition, for some database systems, although these database systems are all constructed in accordance with the standard Structured Query Language (SQL) syntax, due to the different characteristics of different database systems, there are significant differences in the query functions, data types, query structures, etc. supported by different database systems. As a result, different database systems provide database services through different SQL dialects, and there are some compatibility issues between different database systems. For example, SQL statements that can be normally executed in a database system implemented based on SQL dialect 1 cannot be normally executed in a database system implemented based on SQL dialect 2. In this way, in some scenarios (such as database migration, cross-platform query, or distributed data management scenarios), how to implement SQL dialect conversion has become an urgent technical problem to be solved.
[0004] It should be noted that for any database system, the SQL dialect of this database system refers to the version formed after expanding or modifying on the basis of the standard SQL language according to the characteristics of this system itself, so that this SQL dialect can meet the requirements of the database services required by this system itself, so as to subsequently determine the SQL statements of this system according to this SQL dialect, and realize the corresponding query function by executing this SQL statement under this system. Summary of the Invention
[0005] To solve the above technical problems, this application provides a conversion method, device, equipment, medium, and product.
[0006] To achieve the above object, the technical solutions provided by this application are as follows:
[0007] This application provides a conversion method, which includes: obtaining a first Structured Query Language (SQL) statement, where the first SQL statement is a query statement in the SQL dialect of the source database system; retrieving a conversion rule that matches the first SQL statement from a pre-constructed conversion rule library, where the conversion rule library is used to indicate the conversion rules between the SQL dialect of the source database system and the SQL dialect of the target database system, and retrieving information that matches the first SQL statement from at least one database, where the at least one database is determined based on the databases in the source database system and / or the databases in the target database system; generating a prompt word based on the first SQL statement, the matching conversion rule, and the matching information, where the prompt word is used to describe at least one feature of the dialect conversion process implemented using the target model; processing the prompt word using the target model to obtain a second SQL statement, where the second SQL statement is a query statement in the SQL dialect of the target database system.
[0008] In a possible implementation manner, the construction process of the conversion rule library includes: obtaining at least one material, where the at least one material includes one or more of SQL statement pairs obtained through a first method, the system document of the source database system, the system document of the target database system, and conversion experience obtained through a second method. The SQL statement pairs are used to describe the mapping relationship presented by the source database system and the target database system in SQL statements, and the conversion experience is used to describe at least one conversion rule between the SQL dialect of the source database system and the SQL dialect of the target database system; constructing the conversion rule library based on the conversion rules analyzed from the at least one material.
[0009] In a possible implementation manner, the method further includes: determining a retrieval keyword based on the content parsed from the abstract syntax tree of the first SQL statement; the matching conversion rule is obtained by retrieving from the conversion rule library according to the retrieval keyword; the matching information is obtained by retrieving from the at least one database according to the retrieval keyword.
[0010] In a possible implementation manner, after obtaining the second SQL statement, the method further includes: in response to the execution result of the second SQL statement in the target database system indicating a failure, updating the prompt word according to the error message corresponding to the execution result, and continuing to execute the step of processing the prompt word using the target model.
[0011] In a possible implementation, after obtaining the second SQL statement, the method further includes: in response to the execution result of the second SQL statement in the target database system indicating successful execution, obtaining first data from the execution result, where the first data is data obtained by querying in the target database system according to the second SQL statement; in response to determining that the query processing indicated by the second SQL statement in the target database system is different from the query processing indicated by the first SQL statement in the source database system based on the first data, updating the prompt word, and continuing to execute the step of processing the prompt word using the target model.
[0012] In a possible implementation, the method further includes: obtaining second data obtained by querying in the source database system according to the first SQL statement; determining whether the query processing indicated by the second SQL statement in the target database system is the same as the query processing indicated by the first SQL statement in the source database system based on the comparison result between the first data and the second data.
[0013] In a possible implementation, after obtaining the second SQL statement, the method further includes: in response to the query processing indicated by the second SQL statement in the target database system being the same as the query processing indicated by the first SQL statement in the source database system, constructing a correspondence relationship between the second SQL statement and the first SQL statement; updating the conversion rule library according to the correspondence relationship.
[0014] This application provides a conversion device, including: an acquisition unit, configured to acquire a first Structured Query Language (SQL) statement, where the first SQL statement is a query statement in the SQL dialect of the source database system; a retrieval unit, configured to retrieve a conversion rule matching the first SQL statement from a pre-constructed conversion rule library, where the conversion rule library is used to indicate the conversion rule between the SQL dialect of the source database system and the SQL dialect of the target database system, and retrieve information matching the first SQL statement from at least one database, where the at least one database is determined based on the databases in the source database system and / or the databases in the target database system; a generation unit, configured to generate a prompt word according to the first SQL statement, the matching conversion rule, and the matching information, where the prompt word is used to describe at least one feature of the dialect conversion processing implemented by using a target model; a processing unit, configured to process the prompt word by using the target model to obtain a second SQL statement, where the second SQL statement is a query statement in the SQL dialect of the target database system.
[0015] The present application provides an electronic device, which includes: a processor and a memory; the memory is used to store instructions or computer programs; the processor is used to execute the instructions or computer programs in the memory, so that the electronic device executes the conversion method provided by the present application.
[0016] The present application provides a computer-readable medium, in which instructions or computer programs are stored. When the instructions or computer programs run on a device, the device is enabled to execute the conversion method provided by the present application.
[0017] The present application provides a computer program product, which includes a computer program carried on a non-transitory computer-readable medium. The computer program includes program codes for executing the conversion method provided by the present application.
[0018] Compared with the related art, the present application has at least the following advantages:
[0019] The dialect conversion solution provided by the present application includes: first, obtaining a first SQL statement, so that the first SQL statement belongs to a query statement under the SQL dialect of the source database system, so that the first SQL statement can describe a query function of the source database system; then, retrieving a conversion rule matching the first SQL statement from a pre-constructed conversion rule library, so that the matching conversion rule can represent the conversion rule related to the first SQL statement existing in the conversion rule indicating the conversion between the SQL dialect of the source database system and the SQL dialect of the target database system, and retrieving information matching the first SQL statement from at least one database (such as databases in the source database system and / or databases in the target database system), so that the matching information can represent the information related to the first SQL statement existing in these databases, such as table structure, data value, etc.; then, generating a prompt word according to the first SQL statement, the matching conversion rule, and the matching information, so that the prompt word is used to describe at least one feature (such as context, input data, etc.) of the dialect conversion process implemented by the target model; finally, processing the prompt word by the target model to obtain a second SQL statement, so that the second SQL statement belongs to a query statement under the SQL dialect of the target database system, so that any SQL statement of the source database system can be converted into the corresponding SQL statement of the target database system, so as to achieve automatic SQL dialect conversion processing. Description of the Drawings
[0020] To more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the following will briefly introduce the drawings required for use in the description of the embodiments or related technologies. Obviously, the drawings described below are only some embodiments recorded in the present application. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0021] Figure 1 It is a flowchart of a conversion method provided by an embodiment of the present application;
[0022] Figure 2 It is a schematic diagram of an SQL dialect conversion framework provided by an embodiment of the present application;
[0023] Figure 3 It is a schematic structural diagram of a conversion device provided by an embodiment of the present application;
[0024] Figure 4 It is a schematic structural diagram of an electronic device provided by an embodiment of the present application. Detailed implementation manners
[0025] Through research, it is found that in some scenarios, such as in the database migration scenario, in order to reduce costs or improve efficiency, the database (such as stored data + SQL queries) in the old database system can be migrated into the new database system; however, due to the certain differences between the SQL dialects of the old database system and the new database system, in order to achieve this migration, SQL dialect conversion is required. Additionally, in some scenarios, such as in the cross-platform query scenario, in order to better improve the data query service effect, users can query the databases in different database systems with the help of the same query system to achieve the purpose of cross-platform query; however, due to the certain differences between the SQL dialects of the different database systems that can be queried with the help of this query system, in order to achieve cross-platform query, SQL dialect conversion is also required. Furthermore, in some scenarios, such as in the distributed data management scenario, if the distributed data system is built based on the databases in multiple database systems, then users can query the databases in different database systems with the help of this distributed data system; however, due to the certain differences between the SQL dialects of the different database systems involved in this distributed data system, in order to achieve cross-platform query, SQL dialect conversion is also required.
[0026] Through research, it is also found that the goal of SQL dialect conversion is to accurately convert the query statements (such as SQL statements) on one database system into equivalent query statements on another database system to achieve the consistency of query functions.
[0027] It is also found through research that SQL dialect conversion not only needs to consider surface differences (such as syntax differences), but also needs to consider deep - seated differences (such as differences in database - specific functions, data types, query optimization details, query execution plan details, etc.), making it a difficult problem to be solved in research such as database migration, cross - platform query, and distributed data management on how to efficiently and accurately achieve automatic conversion of SQL dialects.
[0028] It is also found through research that SQL dialect conversion can be achieved manually. However, since the SQL dialect conversion rules between different database systems written manually may be incomplete, this affects the SQL dialect conversion rules. In addition, as the number of database systems and SQL dialect types increases, the dimensional difficulty rises sharply. It can be seen that SQL dialect conversion achieved manually not only has a high development cost, but also is difficult to meet complex scenario requirements (such as database migration requirements, etc.), especially in the case of co - existence of multiple SQL dialects.
[0029] It is also found through research that for some machine - learning models, such as large language models (LLMs), the model has powerful code - generation capabilities, enabling the model to quickly generate complex SQL statements with a small amount of context prompts.
[0030] Based on the above research, in order to better improve the SQL dialect conversion effect, the present application provides a conversion method, which includes: first, obtaining a first SQL statement, so that the first SQL statement belongs to a query statement under the SQL dialect of the source database system, so that the first SQL statement can describe a query function of the source database system; then, retrieving a conversion rule matching the first SQL statement from a pre-constructed conversion rule library, so that the matching conversion rule can represent the conversion rule related to the first SQL statement existing in the conversion rule indicating the conversion between the SQL dialect of the source database system and the SQL dialect of the target database system in the conversion rule library, and retrieving information matching the first SQL statement from at least one database (such as the database in the source database system and / or the database in the target database system), so that the matching information can represent the information related to the first SQL statement existing in these databases, such as table structure, data value and other information; then, generating a prompt word based on the first SQL statement, the matching conversion rule, and the matching information, so that the prompt word is used to describe at least one feature (such as context, input data, etc.) of the dialect conversion process implemented by the target model; finally, processing the prompt word by the target model to obtain a second SQL statement, so that the second SQL statement belongs to a query statement under the SQL dialect of the target database system, so that any SQL statement of the source database system can be converted into the corresponding SQL statement of the target database system, so as to achieve automatic SQL dialect conversion, so that SQL dialect conversion can be realized on the premise of reducing or eliminating manual writing of conversion rules, which is beneficial to significantly reducing the development difficulty and workload.
[0031] In addition, the present application does not limit the execution subject of the above conversion method. For example, the method can be applied to a terminal device or a server. For another example, the method can also be implemented by means of data interaction between a terminal device and a server. Among them, the terminal device can be a smart phone, a computer, a personal digital assistant (PDA), a tablet computer, etc. The server can be an independent server, a cluster server or a cloud server.
[0032] In order to enable those skilled in the art to better understand the solution of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0033] To better understand the technical solution provided by this application, the conversion method provided by this application will be described below in conjunction with some drawings. As Figure 1 shown, the conversion method provided by the embodiment of this application includes S1 - S5 below.
[0034] S1: Obtain a first SQL statement, which is a query statement in the SQL dialect of the source database system.
[0035] Among them, the first SQL statement refers to a query statement input by the user and meeting the constraints of the SQL dialect of the source database system (such as Figure 2 the SQL shown 输入 ), so that the first SQL statement belongs to the query statement in the SQL dialect of the source database system, so that the first SQL statement is used to describe a query function in the source database system.
[0036] In addition, this application does not limit the acquisition method of the first SQL statement. For example, it can be provided by the user with the help of a certain input device.
[0037] In addition, in some scenarios, in order to better improve the conversion effect, the user not only provides the first SQL statement that needs to be converted in SQL dialect, but may also provide the identifier of the source database system and the identifier of the target database system, so that it can be accurately known later which database system's query function the first SQL statement is used to describe, and which database system's equivalent query statement the first SQL statement needs to be converted into.
[0038] It should be noted that the source database system refers to the database system to which the query statement that needs to be converted to other SQL dialects belongs, and the target database system refers to the database system to which the query statement obtained through conversion belongs (that is, the database system with this other SQL dialect).
[0039] It should also be noted that a database system (Database System, abbreviated as DBS) is a system composed of a database and the management software of this database. In addition, in a possible implementation manner, the database system may include a database, a Database Management System (DBMS), etc. In addition, different database systems have different SQL dialects.
[0040] S2: Retrieve a conversion rule that matches the first SQL statement from a pre - constructed conversion rule library, where the conversion rule library is used to indicate the conversion rule between the SQL dialect of the source database system and the SQL dialect of the target database system.
[0041] Among them, the conversion rule library refers to a pre-constructed repository for indicating the conversion rules between the SQL dialect of the source database system and the SQL dialect of the target database system (such as the conversion rule repository shown in Figure 2 ), so that some conversion rules (such as the conversion rules obtained by manual writing) are recorded in the conversion rule library.
[0042] In addition, the present application does not limit the construction method of the above conversion rule library. For example, it can be constructed by means of manual work.
[0043] In addition, the above "retrieving the conversion rule matching the first SQL statement from the pre-constructed conversion rule library" means the conversion rule existing in the conversion rule library and related to the first SQL statement.
[0044] Furthermore, the present application does not limit the implementation manner of the above S2. For example, specifically, it can be: retrieving the top K conversion rules most relevant to the first SQL statement from the conversion rule library, where K is a positive integer. It should be noted that the present application does not limit the implementation manner of this retrieval. For example, it can adopt pattern matching at the syntax level or be enhanced by combining semantic information (such as context + query intention) to improve the retrieval accuracy.
[0045] S3: Retrieving the information matching the first SQL statement from at least one database, where the at least one database is determined based on the databases in the source database system and / or the databases in the target database system.
[0046] Among them, the at least one database is used to provide some auxiliary information for the dialect conversion process of the first SQL statement, such as table structure, data type and other information.
[0047] In addition, the present application does not limit the above at least one database. For the sake of understanding, the following will be described in combination with some situations.
[0048] Situation 1, in some scenarios, the above at least one database may include the database in the target database system, so that the information retrieved from the at least one database and matching the first SQL statement can represent the available information existing in the database in the target database system and related to the first SQL statement, such as table definition information (such as table structure, field type, field case) and / or data values (such as some data values obtained by sampling) and other information.
[0049] Case 2. In some scenarios, the above at least one database may include a database in the source database system, so that the information retrieved from the at least one database and matching the first SQL statement can represent the available information related to the first SQL statement existing in the database in the source database system, such as table definition information and / or data value and other information.
[0050] Case 3. In some scenarios, the above at least one database may include a database in the source database system and a database in the target database system, so that the information retrieved from the at least one database and matching the first SQL statement can represent the available information related to the first SQL statement existing in both databases, such as table definition information and / or data value and other information.
[0051] Case 4. In some scenarios, such as in the database migration scenario, if all the data stored in the database in the source database system has been migrated to the database in the target database system, then the above at least one database may include the database of the target database system, so that the information retrieved from the at least one database and matching the first SQL statement can represent the available information related to the first SQL statement existing in both databases.
[0052] In addition, the present application does not limit the relationship between the execution time of the above S3 and the execution time of the above S2. For example, they may be the same or different.
[0053] S4: Generate a prompt word according to the first SQL statement, the matching conversion rule, and the matching information. The prompt word is used to describe at least one feature of the dialect conversion process implemented by the target model.
[0054] Among them, the prompt word (Prompt) is used to describe at least one feature of the dialect conversion process implemented by the target model, such as context (such as the content described by the above matching conversion rule and the above matching information) + the object that needs to be processed for dialect conversion (such as the first SQL statement), etc.
[0055] In addition, the present application does not limit the implementation manner of the prompt words. For example, the prompt words may include some or all of instructions, background information, input data, and output indicators. Among them, the instructions are used to clearly describe what tasks the target model needs to perform or what questions to answer, and the instructions should be clear, specific, and directly related to the task objective (such as the SQL dialect conversion task). The background information is used to describe additional information (such as context) related to the current task or the current question, so that the background information can help the target model better understand the background or context of the current task or the current question. The input data refers to the specific data that needs to be processed or analyzed by the target model (such as the first SQL statement). The output indicator is used to specify the expected output format or structure (such as the structure of the query statement constrained by the SQL dialect of the target database system), so that the output indicator can help the target model generate an output that better meets the current processing requirements (such as SQL dialect conversion requirements).
[0056] Furthermore, the present application does not limit the implementation manner of the target model. For example, the target model can be implemented using any machine learning model with strong code writing ability, such as an LLM.
[0057] S5: Use the target model to process the prompt words to obtain a second SQL statement, which is a query statement in the SQL dialect of the target database system.
[0058] Among them, the second SQL statement refers to the result obtained by converting the dialect of the first SQL statement with the help of the target model, so that the second SQL statement belongs to the query statement in the SQL dialect of the target database system, thereby enabling the second SQL statement to represent a query function in the target database system.
[0059] In addition, the present application does not limit the implementation manner of the above S5. For example, specifically, it can be: input the above prompt words into the target model, so that the target model processes the prompt words to generate and output a second SQL statement, such as Figure 2 the SQL shown 转换 .
[0060] Based on the relevant content of S1 to S5 above, the conversion method provided by this application includes: first, obtaining a first SQL statement so that the first SQL statement belongs to a query statement under the SQL dialect of the source database system, thereby enabling the first SQL statement to describe a query function of the source database system; then, retrieving from a pre-constructed conversion rule library a conversion rule that matches the first SQL statement, so that the matching conversion rule can represent a conversion rule related to the first SQL statement existing in the conversion rules between the SQL dialect of the source database system indicated by the conversion rule library and the SQL dialect of the target database system, and retrieving information that matches the first SQL statement from at least one database (such as a database in the source database system and / or a database in the target database system), so that the matching information can represent information related to the first SQL statement existing in these databases, such as table structure, data values, etc.; then, generating a prompt based on the first SQL statement, the matching conversion rule, and the matching information, so that the prompt is used to describe at least one feature (such as context, input data, etc.) of the dialect conversion process implemented using the target model; finally, processing the prompt using the target model to obtain a second SQL statement, so that the second SQL statement belongs to a query statement under the SQL dialect of the target database system, thus enabling any SQL statement of the source database system to be converted into the corresponding SQL statement of the target database system, achieving automatic SQL dialect conversion, and thus being able to achieve SQL dialect conversion on the premise of reducing or eliminating manual writing of conversion rules, which is conducive to significantly reducing the development difficulty and development workload.
[0061] In addition, to better improve the comprehensiveness of the conversion rules, this application also provides a construction process for the above conversion rule library, which includes steps 11 - 12 below.
[0062] Step 11: Obtain at least one material, where the at least one material includes one or more of SQL statement pairs obtained by the first method, system documents of the source database system, system documents of the target database system, and conversion experience obtained by the second method. The SQL statement pairs are used to describe the mapping relationship presented by the source database system and the target database system in terms of SQL statements, and the conversion experience is used to describe at least one conversion rule between the SQL dialect of the source database system and the SQL dialect of the target database system.
[0063] Among them, the at least one material refers to content related to the SQL dialect of the source database system and the SQL dialect of the target database system obtained through a certain method, so that these materials can describe some mapping relationships between these two SQL dialects.
[0064] In addition, the above at least one material may at least include SQL statement pairs obtained by a first method (such as the SQL pair shown in Figure 2 ), system documents of the source database system (such as the source of the system document shown in Figure 2 ), system documents of the target database system (such as the target of the system document shown in Figure 2 ), and conversion experience obtained by a second method (such as the conversion experience shown in Figure 2 ), one or more of them.
[0065] For the SQL statement pair obtained by the first method, the SQL statement pair is used to describe the mapping relationship presented by the source database system and the target database system in SQL statements (such as query statements) in the form of key-value pairs; moreover, the application does not limit the acquisition method of the SQL statement pair. For example, the SQL statement pair can be obtained by integrating historical manual conversion records, so that the SQL statement pair at least includes SQL statement pairs configured manually, so that the SQL statement pair can represent the conversion rules written manually. It can be seen that in a possible implementation manner, the first method may include a manual method.
[0066] For the system document of the source database system (also called the usage document), the system document is used to describe how to use the source database system for data query, so that the system document can describe as comprehensively as possible the characteristics of the source database system, such as query functions, data types, query structures, etc.
[0067] For the system document of the target database system, the system document is used to describe how to use the target database system for data query, so that the system document can describe as comprehensively as possible the characteristics of the target database system, such as query functions, data types, query structures, etc.
[0068] For the conversion experience obtained by the second method, the conversion experience is used to describe at least one conversion rule between the SQL dialect of the source database system and the SQL dialect of the target database system, such as some implicit conversion rules only known to experts, so that the conversion experience can supplement the conversion rules, so that the conversion rules determined based on the conversion experience are as comprehensive as possible. It can be seen that in a possible implementation manner, the second method may include expert provision.
[0069] Step 12: Construct a conversion rule library according to the conversion rules analyzed from at least one material.
[0070] Among them, the above "conversion rules analyzed from at least one material" refers to the conversion rules obtained by summarizing these materials, such asFigure 2 Function conversion rules, type conversion rules, and query structure conversion rules are shown so that these conversion rules can represent the mapping relationships between different SQL dialects described by these materials.
[0071] It should be noted that the function conversion rules are used to indicate the differences and equivalent mappings of query functions in different database systems; the type conversion rules are used to indicate the differences presented by the same data type in different database systems, such as definition differences, processing method differences, etc. The query structure conversion rules are used to indicate the differences presented by SQL query structures in different database systems at the syntax and logical levels.
[0072] It should also be noted that the present application does not limit the acquisition method of the above-mentioned "conversion rules analyzed from at least one material". For example, specifically, it can be: inputting the prompt words constructed based on the at least one material into the first machine learning model (such as an LLM) so that the first machine learning model can extract and summarize the conversion rules from these materials and output them.
[0073] It has been found through research that for the conversion rules analyzed from at least one material, since there may be some identical or similar conversion rules among these conversion rules, in order to achieve efficient rule retrieval, these conversion rules can be sorted out and stored in an efficient conversion rule library.
[0074] Based on the above research, after analyzing the conversion rules from at least one material, the prompt words constructed based on the conversion rules can be input into the second machine learning model (such as an LLM) so that the second machine learning model can perform some processing on these conversion rules (such as aggregation, sorting, cleaning, etc.) to eliminate the conversion rules without differences and integrate similar conversion rules, and finally obtain and output the conversion rule library so that the conversion rule library can store the conversion rules between the SQL dialect of the source database system and the SQL dialect of the target database system in a more efficient manner for subsequent rapid rule retrieval. It should be noted that the present application does not limit the prompt words. For example, the prompt words can be an efficient Prompt constructed by means of Prompt Engineering.
[0075] Based on the relevant content of the above steps 11 to 12, in this application, the historical manual conversion records (such as SQL statement pairs), various documents of the source database system (such as system documents), various documents of the target database system (such as system documents), and the conversion experience provided by experts are first integrated to extract and summarize the conversion rules. Then, with the help of prompt engineering, an efficient Prompt is constructed based on these conversion rules, and the LLM is used to automatically complete the generation and classification of the rules, obtaining an efficient conversion rule library for subsequent rapid retrieval and use.
[0076] In addition, to better improve the comprehensiveness of the retrieval, this application also provides a retrieval process, which may include the following steps 21 to 23.
[0077] Step 21: Determine the retrieval keywords based on the content parsed from the abstract syntax tree (AST) of the first SQL statement (such as functions, data types, operators, etc.), so that the retrieval keywords can describe some key features of the first SQL statement (such as functions, data types, operators, etc.).
[0078] It should be noted that this application does not limit the implementation manner of the above step 21.
[0079] Step 22: Retrieve from the pre-constructed conversion rule library according to the above retrieval keywords to obtain the conversion rules matching the first SQL statement, so that the matching conversion rules include some conversion rules in the conversion rule library that are most relevant to the retrieval keywords, thereby enabling the matching rules to represent as comprehensively as possible some conversion rules in the conversion rule library that are related to the first SQL statement.
[0080] Step 23: Retrieve from at least one database according to the above retrieval keywords to obtain the information matching the first SQL statement, so that the matching information includes the available information in these databases that is related to the retrieval keywords (such as table structure information, etc.), thereby enabling the matching information to represent as comprehensively as possible some information in these databases that is related to the first SQL statement.
[0081] It should be noted that this application does not limit the relationship between the execution time of the above step 23 and the execution time of the above step 22. For example, they can be the same or different.
[0082] Based on the relevant content of the above steps 21 to 23, after obtaining the first SQL statement that needs to be converted into a dialect, some key features of the first SQL statement can be gradually traversed and queried by parsing the AST of the first SQL statement, and used as retrieval keywords, so as to subsequently retrieve the top K conversion rules most relevant to the first SQL statement from the rule library according to the retrieval keywords, and retrieve the available table definition information and / or data values related to the first SQL statement from the databases in the source database system and the databases in the target database system according to the retrieval keywords, so as to be able to use the information obtained by these retrievals as components of the Prompt of the target model in the future, providing as rich a context as possible for the target model, so that the SQL dialect conversion process implemented based on the information obtained by these retrievals has higher SQL dialect conversion accuracy.
[0083] It has been found through research that in some scenarios, the information carried by the prompt of the target model may be relatively less, so that the SQL statement obtained by processing the prompt using the target model may have some defects, such as syntax errors, semantic errors, etc., resulting in the inability of the SQL statement to be executed normally in the target database system.
[0084] Based on the above research, in order to better improve the conversion accuracy, the present application also provides a possible implementation manner of the conversion method. In this manner, the conversion method may at least include the above S5 and the following step 31. The execution time of step 31 is later than the execution time of S5.
[0085] Step 31: In response to the execution result of the second SQL statement in the target database system indicating a failure, update the prompt according to the error message corresponding to the execution result, and continue to execute the above S5 and its subsequent steps until a preset stop condition is reached.
[0086] Among them, the above "execution result of the second SQL statement in the target database system" is used to describe the execution situation when the second SQL statement is executed in the target database system, so that the execution result can at least indicate whether the second SQL statement is successfully executed in the target database system.
[0087] In addition, for the above "execution result of the second SQL statement in the target database system", if the execution result indicates a failure, the error message that appears when the second SQL statement is executed in the target database system can be collected as the error message corresponding to the execution result, so that the error message can to a certain extent indicate the reason for the failure of the second SQL statement to be executed, and thus the error message can indicate the defects existing in the second SQL statement.
[0088] In addition, the present application does not limit the implementation manner of "updating the prompt word according to the error message corresponding to the execution result". For example, specifically, it may be: adding the error message as new context to the prompt word, so that the context in the prompt word includes not only the existing context (such as the above-mentioned matched conversion rules, the above-mentioned matched information, etc.), but also the newly added context (such as the error message), thereby enabling the prompt word to more comprehensively describe some characteristics of the dialect conversion process implemented by using the target model (such as characteristics like examples of dialect conversion errors), and further making the SQL statement determined through this dialect conversion process more likely to accurately represent the query statement equivalent to the first SQL statement in the target database system.
[0089] Furthermore, in some scenarios, step 31 above may specifically be: in response to the execution result of the second SQL statement in the target database system indicating execution failure, updating the prompt word according to the second SQL statement and the error message corresponding to the execution result, so that the updated prompt word includes the new context generated according to the second SQL statement and the error message, so as to be able to continue to execute step S5 and its subsequent steps based on the updated prompt word until a preset stop condition is reached.
[0090] Among them, the preset stop condition refers to the condition required when ending the iterative update process of the prompt word; and the present application does not limit the implementation manner of the preset stop condition. For example, in some scenarios, the preset stop condition may be: the execution result of the second SQL statement in the target database system indicates execution success.
[0091] Based on the relevant content of the above step 31, after obtaining the second SQL statement output by the target model, the second SQL statement can be executed in the target database system to obtain the execution result of the second SQL statement. So that when it is determined that the execution result is used to indicate that the execution of the second SQL statement fails, it can be determined that the second SQL statement cannot be executed in the target database system, and thus it can be determined that the second SQL statement is defective. Furthermore, it can be determined that the second SQL statement cannot accurately represent the query statement equivalent to the first SQL statement in the target database system. Therefore, error reporting information can be collected and used as the new context to update the prompt words of the target model, so that the updated prompt words include the context generated based on the error reporting information, so that the updated prompt words can accurately represent the reason why the second SQL statement cannot accurately represent the query statement equivalent to the first SQL statement in the target database system, so that the subsequent steps of S5 and its subsequent steps can be returned based on the updated prompt words to implement the next round of SQL dialect conversion processing. Such iterative loops until the iteration loop ends when it is determined that the second SQL statement output by the target model can accurately represent the query statement equivalent to the first SQL statement in the target database system.
[0092] It can be seen that this application guides the target model to continuously repair the errors (such as syntax errors, semantic errors, etc.) that occur when predicting the query statement equivalent to the first SQL statement in the target database system by reconstructing the prompt words of the target model multiple times, so as to ensure that the SQL statement finally output by the target model can accurately represent the query statement equivalent to the first SQL statement in the target database system. In this way, it is possible to effectively avoid the "hallucination" problem (such as problems such as syntax or semantic errors in the SQL output by the target model) by utilizing the understanding ability of the target model for syntax and semantics, which is beneficial to improving the accuracy of the conversion result.
[0093] It has been found through research that in some scenarios, although the second SQL statement output by the target model can be successfully executed in the target database system, in order to better verify whether the conversion is accurate, it can be further determined whether the query function implemented by the second SQL statement in the target database system is equivalent to the query function implemented by the first SQL statement in the source database system.
[0094] Based on the above research, in order to better improve the conversion accuracy, this application also provides a possible implementation manner of the conversion method. In this manner, the conversion method can at least include the above S5 and the following steps 32-step 33. Among them, the execution time of step 32 is later than the execution time of S5.
[0095] Step 32: In response to the execution result of the second SQL statement in the target database system indicating successful execution, obtain first data from the execution result, where the first data is the data obtained by querying in the target database system according to the second SQL statement, so that the first data can represent the query result of the second SQL statement in the target database system.
[0096] Among them, for the above-mentioned "execution result of the second SQL statement in the target database system", if the execution result indicates successful execution, the execution result may also carry the data obtained by querying in the target database system according to the second SQL statement, so that the data can, to a certain extent, represent the query function implemented by the second SQL statement in the target database system, so as to subsequently determine whether the query function implemented by the second SQL statement in the target database system is equivalent to the query function implemented by the first SQL statement in the source database system based on this data.
[0097] Step 33: In response to determining that the query processing indicated by the second SQL statement in the target database system is different from the query processing indicated by the first SQL statement in the source database system based on the first data, update the prompt word, and continue to execute the above S5 and its subsequent steps until a preset stop condition is reached.
[0098] Among them, the above-mentioned "query processing indicated by the second SQL statement in the target database system" refers to the query processing triggered when the second SQL statement is executed in the target database system, so as to represent the query function implemented by the second SQL statement in the target database system.
[0099] The above-mentioned "query processing indicated by the first SQL statement in the source database system" refers to the query processing triggered when the first SQL statement is executed in the source database system, so as to represent the query function implemented by the first SQL statement in the source database system.
[0100] In addition, the present application does not limit the acquisition method of the conclusion that "determine that the query processing indicated by the second SQL statement in the target database system is different from the query processing indicated by the first SQL statement in the source database system based on the first data". For example, specifically, it may be: first obtain the judgment result for the first data, so that the judgment result is used to indicate whether the first data is correct, so that the judgment result can, to a certain extent, represent whether the query function implemented by the second SQL statement in the target database system is equivalent to the query function implemented by the first SQL statement in the source database system, so as to subsequently determine whether the query processing indicated by the second SQL statement in the target database system is the same as the query processing indicated by the first SQL statement in the source database system based on this judgment result.
[0101] In addition, the present application does not limit the manner of obtaining the above "judgment result determined for the first data". For example, in some scenarios, the judgment result may be provided by relevant personnel through an interaction device.
[0102] Furthermore, the present application does not limit the implementation manner of "updating the prompt word" in the above step 33. For example, specifically, it may be: updating the prompt word according to the second SQL statement (such as adding the new context generated according to the second SQL statement to the prompt word), so that the updated prompt word can at least express the semantics that "the query function implemented by the second SQL statement in the target database system is not equivalent to the query function implemented by the first SQL statement in the source database system", so that the target model can learn this semantics from the updated prompt word.
[0103] Moreover, the present application does not limit the implementation manner of the above preset stop condition. For example, the preset stop condition may be: the execution result of the second SQL statement in the target database system indicates successful execution, and the first data carried by the execution result is correct.
[0104] Based on the relevant content of the above steps 32 to 33, it can be seen that after obtaining the second SQL statement output by the target model, it is not only necessary to verify whether the second SQL statement can be normally executed in the target database system, but also necessary to verify whether the query result of the second SQL statement in the target database system is correct, so as to subsequently judge whether the query function implemented by the second SQL statement in the target database system is equivalent to the query function implemented by the first SQL statement in the source database system based on these two verification results. If they are not equivalent, the prompt word of the target model is updated so that the updated prompt word can add the context that "the query function implemented by the second SQL statement in the target database system is not equivalent to the query function implemented by the first SQL statement in the source database system", so as to subsequently return and continue to execute the above S5 and its subsequent steps based on the updated prompt word to implement the next round of SQL dialect conversion processing, and iterate in this way until it is determined that the second SQL statement output by the target model can accurately represent the equivalent query statement of the first SQL statement in the target database system, and then the iteration loop ends.
[0105] It has been found through research that in some scenarios, such as the database migration scenario, the data stored in the database in the target database system includes the data added by migrating the data stored in the database in the source database system, so that the query results obtained for the same query function in these two databases are the same.
[0106] Based on the above research, in order to better reduce the conversion cost, the present application also provides a possible implementation manner of the conversion method. In this manner, the conversion method may at least include the following steps 41-step 42.
[0107] Step 41: Obtain the second data obtained by querying in the source database system according to the first SQL statement, so that the second data is the query result of the first SQL statement in the source database system, thereby enabling the second data to represent to a certain extent the query function implemented by the first SQL statement in the source database system.
[0108] It should be noted that the present application does not limit the execution time of step 41, and only needs to ensure that the execution time of step 41 is earlier than the execution time of the following step 42.
[0109] Step 42: Determine whether the query processing indicated by the second SQL statement in the target database system is the same as the query processing indicated by the first SQL statement in the source database system according to the comparison result between the first data and the second data.
[0110] In the present application, after obtaining the first data obtained by querying in the target database system according to the second SQL statement and the second data obtained by querying in the source database system according to the first SQL statement, the first data and the second data can be compared to obtain a comparison result, so that the comparison result is used to indicate whether the first data and the second data are the same; if the comparison result indicates that the first data is different from the second data, it can be determined that the first data is incorrect, and thus it can be determined that the query function implemented by the second SQL statement in the target database system is not equivalent to the query function implemented by the first SQL statement in the source database system, and further it can be determined that the query processing indicated by the second SQL statement in the target database system is different from the query processing indicated by the first SQL statement in the source database system; however, if the comparison result indicates that the first data and the second data are the same, it can be determined that the first data is correct, and thus it can be determined that the query function implemented by the second SQL statement in the target database system is equivalent to the query function implemented by the first SQL statement in the source database system, and further it can be determined that the query processing indicated by the second SQL statement in the target database system is the same as the query processing indicated by the first SQL statement in the source database system.
[0111] Based on the relevant content of the above steps 41 to 42, it can be known that in some scenarios, such as the database migration scenario, since the data stored in the database in the target database system includes the data stored in the database in the source database system, so that the query results obtained by the same query function in these two databases are the same. Therefore, it is possible to determine whether the second SQL statement can accurately represent the equivalent query statement of the first SQL statement in the target database system by comparing the query result of the second SQL statement in the target database system with the query result of the second SQL statement in the target database system (such as Figure 2 the query result comparison method shown).
[0112] It has been found through research that for some scenarios, such as cross-platform query scenarios or distributed data management scenarios, since the data stored in different databases involved in these scenarios may have certain differences, the query results obtained by the same query function in different databases may be different.
[0113] Based on the above research, in order to better improve the conversion accuracy, the present application also provides a possible implementation manner of the conversion method. In this manner, the conversion method may at least include the following steps 51-step 52.
[0114] Step 51: Obtain the tag data corresponding to the first SQL statement. The tag data is the data obtained by querying and processing the target database system according to the query processing indicated by the first SQL statement in the source database system, so that the tag data can be used as guiding information to guide the target model to output the equivalent query statement of the first SQL statement in the target database system.
[0115] It should be noted that the present application does not limit the acquisition method of the above tag data. For example, it can be obtained by manual annotation.
[0116] For another example, the tag data corresponding to the above first SQL statement can be obtained by querying from the target database system through a manual query method. It should be noted that the present application does not limit the manual query method. For example, it can be: after relevant personnel analyze the query processing indicated by the first SQL statement in the source database system, relevant personnel gradually reproduce the query processing in the target database system to obtain the tag data corresponding to the first SQL statement.
[0117] It should be noted that the present application does not limit the execution time of step 51, as long as the execution time of step 51 is earlier than the execution time of the following step 52.
[0118] For another example, in order to better reduce manual intervention, step 51 may specifically be as follows: after obtaining the second data obtained by querying in the source database system according to the first SQL statement, if the comparison result between the first data and the second data indicates that the first data is the same as the second data, it is determined that the query process indicated by the second SQL statement in the target database system is the same as the query process indicated by the first SQL statement in the source database system; however, if the comparison result between the first data and the second data indicates that the first data is different from the second data, it can be speculated that the difference may be caused by different data stored in the database. Therefore, a data request can be sent to the user so that the data request is used to request the user to provide the tag data corresponding to the first SQL statement, so that the data provided by the user can be used as the tag data corresponding to the first SQL statement for subsequent verification processes (such as the verification process shown in step 52 below).
[0119] Step 52: Determine whether the query process indicated by the second SQL statement in the target database system is the same as the query process indicated by the first SQL statement in the source database system according to the comparison result between the first data and the tag data corresponding to the first SQL statement.
[0120] It should be noted that the embodiments of step 52 in this application are not limited. For example, it may specifically be as follows: after obtaining the first data obtained by querying in the target database system according to the second SQL statement, the first data can be compared with the tag data corresponding to the first SQL statement to obtain a comparison result, so that the comparison result is used to indicate whether the first data is the same as the tag data; if the comparison result indicates that the first data is different from the tag data, it can be determined that the first data is incorrect, and thus it can be determined that the query process indicated by the second SQL statement in the target database system is different from the query process indicated by the first SQL statement in the source database system; however, if the comparison result indicates that the first data is the same as the tag data, it can be determined that the first data is correct, and thus it can be determined that the query process indicated by the second SQL statement in the target database system is the same as the query process indicated by the first SQL statement in the source database system.
[0121] Based on the relevant content of steps 51 to 52 above, it can be seen that in some scenarios, such as cross-platform query scenarios or distributed data management scenarios, due to certain differences in the data stored in the databases of different database systems, the query results obtained by the same query function in different databases are different. Therefore, an artificial assistance method can be used to determine whether the second SQL statement can accurately represent the equivalent query statement of the first SQL statement in the target database system, so that the conversion scheme provided by this application can be applied to more scenarios.
[0122] It has been found that in some cases, such as when the query function of the source database system is enhanced or the application scenario of the source database system changes, etc., the already constructed conversion rule library may not be able to comprehensively describe the conversion rules between the SQL dialect of the source database system and the SQL dialect of the target database system.
[0123] Based on the above research, in order to better improve the comprehensiveness of dialect conversion, the present application also provides a possible implementation manner of the conversion method. In this manner, the conversion method may at least include the following steps 61 - step 62. Among them, the execution time of step 61 is later than the execution time of S5 above.
[0124] Step 61: In response to the query processing indicated by the second SQL statement in the target database system being the same as the query processing indicated by the first SQL statement in the source database system (such as reaching a preset stop condition), construct a correspondence relationship between the second SQL statement and the first SQL statement, such as Figure 2 shown in <SQL 输入 , SQL 转换 >.
[0125] Step 62: Update the conversion rule library according to the correspondence relationship between the second SQL statement and the first SQL statement, so that the updated conversion rule library can describe the conversion rules indicated by this correspondence relationship.
[0126] It should be noted that the present application does not limit the implementation manner of "updating the conversion rule library according to the correspondence relationship between the second SQL statement and the first SQL statement". For example, when the conversion rule library is constructed based on at least one piece of material, it may specifically be: first use this correspondence relationship to update at least one piece of material (for example, add this correspondence relationship as a new SQL statement pair to at least one piece of material), so that the updated at least one piece of material includes this correspondence relationship; then perform a conversion rule library construction process (such as the construction process shown in step 12 above) based on the updated at least one piece of material to obtain an updated conversion rule library, so that the updated conversion rule library can describe the conversion rules indicated by this correspondence relationship.
[0127] Based on the relevant contents of steps 61 to 62 above, it can be known that after obtaining the second SQL statement output by the target model, if the second SQL statement can be successfully executed in the target database system, and the query result of the second SQL statement in the target database system is correct, it can be determined that the second SQL statement can accurately represent the query statement equivalent to the first SQL statement in the target database system, so a correspondence between the second SQL statement and the first SQL statement can be constructed, so that the correspondence can represent the conversion rule used in this conversion process, so that the correspondence can be subsequently updated as a new conversion rule to the conversion rule library, which is conducive to better improving and expanding the coverage of the conversion rule library.
[0128] Based on the above conversion method, it can be seen that in a possible implementation mode, the SQL dialect conversion solution provided by this application (such as Figure 2 The solution described by the SQL dialect conversion framework shown in the figure) can include an offline rule generation process, an online retrieval process, a query statement conversion and a feedback process. For ease of understanding, each process is introduced below.
[0129] ① The relevant contents of the offline rule generation process are as follows: In the offline rule generation stage, first summarize the historical manual conversion records (such as SQL statement pairs), relevant documents of the source database system (such as system documents), relevant documents of the target database system (such as system documents), and conversion experience provided by experts to obtain some conversion rules, such as function conversion rules, type conversion rules, query structure conversion rules, etc.; then, these conversion rules are processed (aggregation, sorting, cleaning, etc.) to build an efficient conversion rule library for subsequent retrieval and use.
[0130] In addition, in order to ensure the quality and practicality of the conversion rules, after some conversion rules are extracted from the material, these conversion rules can be aggregated, sorted, cleaned, etc. in a certain way (such as with the help of LLM or other automated processing methods) to eliminate conversion rules with no differences and integrate similar conversion rules to avoid redundancy in the conversion rule library, thereby ensuring that the final constructed conversion rule library is an efficient warehouse; and the generation process of the conversion rule library provided by the present application has dynamic expansion capabilities, and new conversion rules can be continuously added in subsequent processes to adapt to the needs of new database systems or existing database systems applied to new business scenarios.
[0131] It can be seen that the conversion rule library provided by this application not only lays a solid foundation for the efficient conversion of SQL dialects, but also provides reliable data support for subsequent rule retrieval and reuse, so as to significantly reduce manual intervention in subsequent applications (such as online rule retrieval), improve the accuracy and efficiency of conversion, and further promote the automation process in related fields of database migration and management.
[0132] ② The relevant content of the online retrieval process is as follows: The task in the online retrieval stage is to construct a Prompt for implementing SQL dialect conversion, so that the input of this task is the query statement to be converted (such as the first SQL statement above), and this task is implemented based on an effective rule retrieval and Prompt construction method to ensure that an accurate SQL dialect conversion result can be efficiently generated based on this Prompt subsequently.
[0133] In addition, this application parses the query syntax tree of the query statement to be converted to obtain some key features (such as functions, data types, operators, etc.); then, it retrieves the conversion rules related to these key features in the conversion rule library as the conversion rules matching the query statement to be converted, and retrieves the information related to these key features (such as table definition information + data values, etc.) from the source / target database as the information matching the query statement to be converted, so as to subsequently construct a Prompt based on the matching conversion rules and the matching information as the context, so that this Prompt can provide relatively rich context for the target model used to implement SQL dialect conversion, which is conducive to improving conversion accuracy.
[0134] ③ The relevant content of the query statement conversion and feedback process is as follows: In the query statement conversion and feedback stage, the prompt words to be input to the target model (such as LLM) can be constructed according to the retrieved rules and information, so that the target model can subsequently generate the query statement under the target database system under the guidance of these prompt words, and continuously verify and optimize the conversion result and the conversion rule library in combination with the feedback mechanism to ensure the accuracy of conversion and improve the comprehensiveness of the conversion rule library. Among them, because the construction of this prompt word fully considers the retrieved conversion rules, table definition information, data values and other information, so that this prompt word can better guide the target model to generate a query statement that conforms to the syntax and semantics of the SQL dialect of the target database system, which is conducive to improving conversion accuracy.
[0135] In addition, the verification process of the conversion result can be as follows: after generating the SQL conversion result using the target model, the conversion result can be verified by actually executing it in the target database system; if the query execution is successful and the result is correct, it can be determined that the verification is successful, so this conversion process can be recorded, and the new conversion record can be updated to the conversion rule library to further improve and expand the coverage of the conversion rule library; if the query execution fails or the result is incorrect, the error message can be collected and used as the new context, so that the target model can be gradually guided to repair the conversion error by reconstructing the Prompt multiple times, thus effectively avoiding the "hallucination" problem and further improving the reliability of the conversion result.
[0136] Based on the relevant content from ① to ③ above, for the SQL dialect conversion framework provided in this application, this framework extracts and summarizes some conversion rules by integrating historical manual conversion records (such as SQL statement pairs), relevant documents of the source database system (such as system documents), relevant documents of the target database system (such as system documents), and conversion experience provided by experts, so as to store these conversion rules in an efficient conversion rule library after sorting for subsequent rapid retrieval and use. In actual application, this framework retrieves the relevant conversion rules and relevant information in the database according to the SQL statement input by the user, and completes the automatic conversion with the help of the LLM. In addition, this framework continuously optimizes and improves the generated conversion result by introducing a feedback mechanism to continuously improve the SQL dialect conversion effect.
[0137] Based on the relevant content of the above conversion scheme, the conversion scheme provided in this application has the advantages shown in (1)-(5) below.
[0138] (1) This application automatically establishes and dynamically improves the conversion rule library for SQL dialects between different database systems. Specifically, this application provides a method for automatically generating dialect conversion rules and constructing a conversion rule repository based on a machine learning model (such as LLM) and combining historical conversion data, system documents and other materials, so that this application constructs an extensible conversion rule library through a combination of manual experience + automatic generation method, enabling the conversion rule library to be continuously optimized and expanded to meet the complex conversion requirements between different database systems.
[0139] (2) The conversion scheme provided in this application can efficiently complete database migration. Specifically, this application greatly reduces the complexity and labor cost of database migration and improves the migration efficiency and accuracy through an automated dialect conversion process and a precise rule matching mechanism.
[0140] (3) The conversion solution provided by this application presents high reliability and consistency in SQL dialect conversion. Specifically: this application corrects the errors in the generated SQL conversion result through a feedback mechanism to ensure the syntactic and semantic correctness of the conversion result, which is conducive to improving compatibility and consistency in a multi-database environment.
[0141] (4) The conversion solution provided by this application is applicable to diverse business scenarios. Specifically: this conversion solution has strong expansion capabilities and can handle a large number of similar queries in specific business scenarios, thereby achieving efficient reuse of rules and significantly improving conversion performance. It can be seen that when this conversion solution is applied to certain business scenarios, such as business scenarios with a large number of query requests with similar structures or the same logic, this conversion solution can make full use of existing rules (that is, the conversion rules recorded in the conversion rule library) to achieve efficient conversion reuse. Rule reuse not only significantly reduces the development cost of manually writing conversion logic but also can greatly improve the accuracy, consistency, and maintainability of conversion. In addition, this conversion solution has dynamic expansion capabilities and can flexibly update the conversion rule library as the conversion scenario (such as the application scenario of an existing database system) and database characteristics (such as the query function of an existing database system) change to adapt to changing business requirements.
[0142] (5) The conversion solution provided by this application not only simplifies the difficulty of database migration and cross-platform queries but also provides an efficient and scalable solution to the SQL compatibility problem in complex systems (such as distributed data systems). This opens up a new research direction for the related fields of database management and migration and also provides strong technical support for users to achieve efficient queries in a multi-database environment.
[0143] Based on the conversion method provided by the embodiments of this application, the embodiments of this application also provide a conversion device. The following will be explained and described in conjunction with Figure 3 Among them, Figure 3 is a schematic structural diagram of a conversion device provided by the embodiments of this application. It should be noted that for the technical details of the conversion device provided by the embodiments of this application, please refer to the relevant content of the above conversion method.
[0144] As Figure 3 shown, the conversion device 300 provided by the embodiments of this application includes:
[0145] An acquisition unit 301, configured to acquire a first Structured Query Language (SQL) statement, where the first SQL statement is a query statement in the SQL dialect of the source database system;
[0146] A retrieval unit 302, configured to retrieve a conversion rule that matches the first SQL statement from a pre-constructed conversion rule library, where the conversion rule library is used to indicate conversion rules between the SQL dialects of the source database system and the target database system, and to retrieve information that matches the first SQL statement from at least one database, where the at least one database is determined based on the databases in the source database system and / or the databases in the target database system;
[0147] A generation unit 303, configured to generate a prompt word based on the first SQL statement, the matched conversion rule, and the matched information, where the prompt word is used to describe at least one feature of the dialect conversion processing implemented by using a target model;
[0148] A processing unit 304, configured to process the prompt word by using the target model to obtain a second SQL statement, where the second SQL statement is a query statement in the SQL dialect of the target database system.
[0149] In a possible implementation manner, the process of constructing the conversion rule library includes: obtaining at least one material, where the at least one material includes one or more of SQL statement pairs obtained by a first method, system documents of the source database system, system documents of the target database system, and conversion experience obtained by a second method, where the SQL statement pairs are used to describe the mapping relationship presented by the source database system and the target database system in SQL statements, and the conversion experience is used to describe at least one conversion rule between the SQL dialects of the source database system and the target database system; constructing the conversion rule library according to the conversion rules analyzed from the at least one material.
[0150] In a possible implementation manner, the conversion device 300 further includes: a parsing unit, configured to determine a retrieval keyword according to the content parsed from the abstract syntax tree of the first SQL statement; the matched conversion rule is obtained by retrieving from the conversion rule library according to the retrieval keyword; the matched information is obtained by retrieving from the at least one database according to the retrieval keyword.
[0151] In a possible implementation manner, the conversion device 300 further includes: a first update unit, configured to, after obtaining the second SQL statement, in response to the execution result of the second SQL statement in the target database system indicating a failure, update the prompt word according to the error message corresponding to the execution result, and continue to execute the step of processing the prompt word by using the target model.
[0152] In a possible implementation, the conversion device 300 further includes: a second update unit, configured to, after obtaining the second SQL statement, in response to the execution result of the second SQL statement in the target database system indicating successful execution, obtain first data from the execution result, where the first data is data obtained by querying in the target database system according to the second SQL statement; in response to determining that the query process indicated by the second SQL statement in the target database system is different from the query process indicated by the first SQL statement in the source database system based on the first data, update the prompt word, and continue to execute the step of processing the prompt word using the target model.
[0153] In a possible implementation, the conversion device 300 further includes: a verification unit, configured to obtain second data obtained by querying in the source database system according to the first SQL statement; determine whether the query process indicated by the second SQL statement in the target database system is the same as the query process indicated by the first SQL statement in the source database system based on the comparison result between the first data and the second data.
[0154] In a possible implementation, the conversion device 300 further includes: a third update unit, configured to, after obtaining the second SQL statement, in response to the query process indicated by the second SQL statement in the target database system being the same as the query process indicated by the first SQL statement in the source database system, construct a correspondence relationship between the second SQL statement and the first SQL statement; update the conversion rule library according to the correspondence relationship.
[0155] Based on the relevant content of the above conversion device 300, the working principle of the device 300 includes: first, obtaining a first SQL statement, so that the first SQL statement belongs to a query statement under the SQL dialect of the source database system, so that the first SQL statement can describe a query function of the source database system; then, retrieving a conversion rule matching the first SQL statement from a pre-constructed conversion rule library, so that the matching conversion rule can represent a conversion rule related to the first SQL statement existing in the conversion rule between the SQL dialect of the source database system and the SQL dialect of the target database system indicated by the conversion rule library, and retrieving information matching the first SQL statement from at least one database (such as a database in the source database system and / or a database in the target database system), so that the matching information can represent information related to the first SQL statement existing in these databases, such as table structure, data value, etc.; then, generating a prompt word according to the first SQL statement, the matching conversion rule, and the matching information, so that the prompt word is used to describe at least one feature (such as context, input data, etc.) of the dialect conversion process implemented by the target model; finally, processing the prompt word by the target model to obtain a second SQL statement, so that the second SQL statement belongs to a query statement under the SQL dialect of the target database system, so that any SQL statement of the source database system can be converted into the corresponding SQL statement of the target database system, so as to achieve automatic SQL dialect conversion processing.
[0156] In addition, an embodiment of the present application further provides an electronic device, the device includes a processor and a memory: the memory is used to store instructions or computer programs; the processor is used to execute the instructions or computer programs in the memory, so that the electronic device executes any implementation manner of the conversion method provided by the embodiment of the present application.
[0157] See Figure 4 , which shows a schematic structural diagram of an electronic device 400 suitable for implementing the embodiments of the present disclosure. The terminal devices in the embodiments of the present disclosure may include, but are not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Tablet Computers), PMPs (Portable Multimedia Players), vehicle terminals (such as vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 4 The electronic device shown is only an example and should not bring any limitation to the functions and usage scope of the embodiments of the present disclosure.
[0158] Such as Figure 4As shown, the electronic device 400 may include a processing device (such as a central processing unit, a graphics processing unit, etc.) 401, which may perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 402 or a program loaded from a storage device 408 into a random access memory (RAM) 403. In the RAM 403, various programs and data required for the operation of the electronic device 400 are also stored. The processing device 401, the ROM 402, and the RAM 403 are connected to each other through a bus 404. An input / output (I / O) interface 405 is also connected to the bus 404.
[0159] Generally, the following devices may be connected to the I / O interface 405: an input device 406 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 407 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 408 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 409. The communication device 409 may allow the electronic device 400 to communicate with other devices wirelessly or wiredly to exchange data. Although Figure 4 the electronic device 400 with various devices is shown, it should be understood that it is not required to implement or have all the shown devices. Instead, more or fewer devices may be implemented or had.
[0160] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart may be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program contains program codes for performing the method shown in the flowchart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication device 409, or installed from the storage device 408, or installed from the ROM 402. When the computer program is executed by the processing device 401, the above functions defined in the method of the embodiment of the present disclosure are executed.
[0161] The electronic device provided by the embodiment of the present disclosure and the method provided by the above embodiment belong to the same inventive concept. Technical details not described in detail in this embodiment may be referred to the above embodiment, and this embodiment has the same beneficial effects as the above embodiment.
[0162] An embodiment of the present application also provides a computer-readable medium, in which instructions or a computer program are stored. When the instructions or the computer program run on a device, the device is caused to execute any implementation manner of the conversion method provided by the embodiment of the present application.
[0163] It should be noted that the above-mentioned computer-readable medium in the present disclosure may be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. A computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium that contains or stores a program, and this program can be used by or in combination with an instruction execution system, apparatus, or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, and this computer-readable signal medium can send, propagate, or transmit a program for use by or in combination with an instruction execution system, apparatus, or device. The program code contained on a computer-readable medium can be transmitted by any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0164] In some embodiments, the client and the server can communicate using any currently known or future-developed network protocol such as HTTP (Hyper Text Transfer Protocol), and can be interconnected with digital data communication in any form or medium (e.g., a communication network). Examples of communication networks include local area networks ("LAN"), wide area networks ("WAN"), the Internet (e.g., the Internet), and end-to-end networks (e.g., ad hoc end-to-end networks), as well as any currently known or future-developed networks.
[0165] The above-mentioned computer-readable medium may be included in the above-mentioned electronic device; or it may exist separately without being assembled into the electronic device.
[0166] The above-mentioned computer-readable medium carries one or more programs, and when the above-mentioned one or more programs are executed by the electronic device, the electronic device can execute the above-mentioned method.
[0167] Computer program code for performing the operations of this disclosure can be written in one or more programming languages or combinations thereof. The programming languages include, but are not limited to, object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, executed as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any kind of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0168] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in the flowchart or block diagram can represent a module, a segment of a program, or a part of code that contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks can occur in a different order than that marked in the accompanying drawings. For example, two consecutive blocks shown can actually be executed substantially in parallel, and they can sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and combinations of blocks in the block diagram and / or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.
[0169] The units involved in the embodiments described in this disclosure can be implemented in software or in hardware. Among them, the name of the unit / module does not constitute a limitation to the unit itself in some cases.
[0170] The functions described above in this document can be performed at least in part by one or more hardware logic components. For example, by way of non-limitation, exemplary types of hardware logic components that can be used include: field programmable gate arrays (FPGA), application specific integrated circuits (ASIC), application specific standard products (ASSP), system on a chip (SOC), complex programmable logic devices (CPLD), and so on.
[0171] In the context of the present disclosure, a machine-readable medium can be a tangible medium that can contain or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. The machine-readable medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of the machine-readable storage medium would include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0172] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. For the same or similar parts among the various embodiments, reference can be made to each other. For the systems or apparatuses disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple, and reference can be made to the description in the method part for the relevant parts.
[0173] It should be understood that in this application, "at least one (item)" means one or more, and "a plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships can exist. For example, "A and / or B" can mean: only A exists, only B exists, and both A and B exist simultaneously. Here, A and B can be singular or plural. The character " / " generally indicates that the associated objects before and after are in an "or" relationship. "At least one (one) of the following" or its similar expressions refer to any combination of these items, including any combination of single items (ones) or plural items (ones). For example, at least one (one) of a, b, or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.
[0174] It should also be noted that in this text, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements not only includes those elements, but also includes other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising a..." does not exclude the presence of additional identical elements in the process, method, article or device comprising said element.
[0175] The steps of the methods or algorithms described in connection with the embodiments disclosed herein may be implemented directly in hardware, in a software module executed by a processor, or in a combination thereof. The software module may be placed in a random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium well known in the art.
[0176] The foregoing description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Thus, the present application is not intended to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A conversion method, characterized in that: The method comprises: Obtaining a first structured query language SQL statement, where the first SQL statement is a query statement in the SQL dialect of the source database system; Retrieving a conversion rule matching the first SQL statement from a pre-built conversion rule library, the conversion rule library being used to indicate conversion rules between the SQL dialect of the source database system and the SQL dialect of the target database system, and retrieving information matching the first SQL statement from at least one database, the at least one database being determined based on a database in the source database system and / or a database in the target database system; Generate a prompt word according to the first SQL statement, the matched conversion rule, and the matched information, wherein the prompt word is used to describe at least one feature of the dialect conversion process implemented by using the target model; The prompt word is processed using the target model to obtain a second SQL statement, where the second SQL statement is a query statement in the SQL dialect of the target database system.
2. The method according to claim 1, characterized in that: The construction process of the conversion rule base includes: Acquire at least one material, the at least one material comprising one or more of an SQL statement pair acquired in a first manner, a system document of the source database system, a system document of the target database system, and a conversion experience acquired in a second manner, the SQL statement pair being used to describe a mapping relationship between the source database system and the target database system in SQL statements, and the conversion experience being used to describe at least one conversion rule between an SQL dialect of the source database system and an SQL dialect of the target database system; The conversion rule library is constructed according to the conversion rule analyzed from the at least one material.
3. The method according to claim 1, characterized in that The method further comprises: Determine a search keyword based on the content parsed from the abstract syntax tree of the first SQL statement; The matching conversion rule is obtained by searching the conversion rule library according to the search keyword; The matching information is obtained by searching the at least one database according to the search keyword.
4. The method according to claim 1, characterized in that: After obtaining the second SQL statement, the method further includes: In response to the execution result of the second SQL statement in the target database system indicating execution failure, the prompt word is updated according to error information corresponding to the execution result, and the step of processing the prompt word using the target model is continued.
5. The method according to claim 1, characterized in that After obtaining the second SQL statement, the method further includes: In response to an execution result of the second SQL statement in the target database system indicating that the execution is successful, obtaining first data from the execution result, where the first data is data obtained by querying the target database system according to the second SQL statement; In response to determining, based on the first data, that the query processing indicated by the second SQL statement in the target database system is different from the query processing indicated by the first SQL statement in the source database system, the prompt word is updated, and the step of processing the prompt word using the target model is continued.
6. The method according to claim 5, characterized in that The method further comprises: Acquire second data obtained by querying the source database system according to the first SQL statement; According to the comparison result between the first data and the second data, it is determined whether the query processing indicated by the second SQL statement in the target database system is the same as the query processing indicated by the first SQL statement in the source database system.
7. The method according to claim 1, characterized in that After obtaining the second SQL statement, the method further includes: In response to the query processing indicated by the second SQL statement in the target database system being the same as the query processing indicated by the first SQL statement in the source database system, establishing a correspondence relationship between the second SQL statement and the first SQL statement; The conversion rule base is updated according to the corresponding relationship.
8. A conversion device, characterized in that: include: An acquisition unit, configured to acquire a first structured query language SQL statement, where the first SQL statement is a query statement in the SQL dialect of the source database system; a retrieval unit, configured to retrieve a conversion rule matching the first SQL statement from a pre-built conversion rule library, the conversion rule library being used to indicate conversion rules between the SQL dialect of the source database system and the SQL dialect of the target database system, and to retrieve information matching the first SQL statement from at least one database, the at least one database being determined based on a database in the source database system and / or a database in the target database system; A generating unit, configured to generate a prompt word according to the first SQL statement, the matched conversion rule, and the matched information, wherein the prompt word is used to describe at least one feature of the dialect conversion process implemented by using the target model; The processing unit is used to process the prompt word by using the target model to obtain a second SQL statement, where the second SQL statement is a query statement in the SQL dialect of the target database system.
9. An electronic device, characterized in that: The device comprises: a processor and a memory; The memory is used to store instructions or computer programs; The processor is used to execute the instructions or computer programs in the memory so that the electronic device executes the method according to any one of claims 1 to 7.
10. A computer-readable medium, characterized in that The computer-readable medium stores instructions or computer programs, and when the instructions or computer programs are executed on a device, the device is enabled to execute the method according to any one of claims 1 to 7.
11. A computer program product, characterized in that It comprises a computer program carried on a non-transitory computer-readable medium, the computer program comprising a program code for executing the method according to any one of claims 1 to 7.
Citation Information
Cited By
Digital main line automatic modeling method and system based on large language model
CN120523828A
Database mapping file conversion method and system based on large model
CN120631967A
Structured query statement generation method and device and related product
CN121658508A