Transcoding method and apparatus, computer device, and storage medium

By setting up a code conversion terminal between the code storage terminal and the data testing terminal, and utilizing syntax information difference comparison and function mapping relationships, the original code is automatically converted into the target code, solving the problem of time-consuming manual conversion and achieving efficient code conversion and data testing.

CN115543339BActive Publication Date: 2026-02-03CHINA PING AN LIFE INSURANCE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211247567.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-12
Publication Date
2026-02-03
Estimated Expiration
2042-10-12

AI Technical Summary

Technical Problem

In existing technologies, manually converting the code of the first data platform into the code of the second data platform is time-consuming and affects the efficiency of code conversion.

Method used

By setting up a code conversion terminal between the code storage terminal and the data testing terminal, the original syntax information in the original code is obtained and compared with the target syntax information. The target function statements are then selected and concatenated with the original non-function statements to form the target code.

Benefits of technology

This improves the efficiency of code conversion, enabling the target code to be executed directly on the data testing end, thus improving the efficiency of data testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115543339B_ABST
    Figure CN115543339B_ABST
Patent Text Reader

Abstract

The embodiment of the application provides a code conversion method and device, computer equipment and a storage medium, and belongs to the technical field of artificial intelligence. The method comprises the following steps: obtaining an original code; wherein the original code comprises an original function statement and an original non-function statement; obtaining original syntax information according to an original function name of the original function statement; performing differential comparison on the original syntax information and preset target syntax information to obtain to-be-converted syntax information; obtaining function information of the original function statement according to the to-be-converted syntax information; screening a target function statement from a preset candidate function mapping relationship according to the function information; and performing splicing processing on the target function statement and the original non-function statement to obtain a target code. The embodiment of the application can improve the code conversion efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of artificial intelligence, and particularly relates to a code conversion method and device, computer equipment and a storage medium. BACKGROUND

[0002] During data testing, the code of a first data platform needs to be converted into code suitable for a second data platform. In related technologies, the code of the first data platform is manually converted into code that conforms to the syntax of the second data platform. However, the first data platform stores a huge amount of data, and manual code conversion requires a large amount of time and affects the efficiency of code conversion. SUMMARY

[0003] The main purpose of the embodiments of the present application is to provide a code conversion method and device, computer equipment and a storage medium, which aims to improve the efficiency of code conversion.

[0004] To achieve the above purpose, a first aspect of the embodiments of the present application provides a code conversion method, which comprises:

[0005] obtaining original code; wherein the original code comprises original function statements and original non-function statements;

[0006] obtaining original syntax information according to the original function name of the original function statement;

[0007] differentially comparing the original syntax information and preset target syntax information to obtain to-be-converted syntax information;

[0008] obtaining function information of the original function statement according to the to-be-converted syntax information;

[0009] selecting a target function statement from a preset candidate function mapping relationship according to the function information;

[0010] splicing the target function statement and the original non-function statement to obtain target code.

[0011] In some embodiments, the function information comprises function categories and function function information; and the step of selecting a target function statement from a preset candidate function mapping relationship according to the function information comprises:

[0012] selecting a target function mapping relationship from the candidate function mapping relationship according to the function categories; wherein the target function mapping relationship comprises at least one candidate function statement;

[0013] selecting the target function statement from the candidate function statement according to the function function information.

[0014] In some embodiments, the filtering the target function statement from the candidate function statement according to the function function information comprises:

[0015] filtering a selected function statement from the candidate function statement according to the function function information;

[0016] determining a priority of the selected function statement according to a preset priority determination rule, to obtain a function level;

[0017] filtering the target function statement from the selected function statement according to the function level.

[0018] In some embodiments, before the filtering the target function statement from the preset candidate function mapping relationship according to the function information, the method further comprises:

[0019] constructing the candidate function mapping relationship, specifically comprising:

[0020] obtaining candidate function information of the candidate function statement;

[0021] constructing a mapping relationship between the original function statement and the candidate function statement according to the function function information and the candidate function information, to obtain the candidate function mapping relationship.

[0022] In some embodiments, after the splicing the target function statement and the original non-function statement to obtain the target code, the method further comprises:

[0023] constructing a code mapping relationship, specifically comprising:

[0024] obtaining creation information of the target code; wherein the creation information comprises: creation time information, conversion user information, table creation identification information and code creation identification information;

[0025] constructing a mapping relationship between the original code and the target code according to the creation information, to obtain the code mapping relationship.

[0026] In some embodiments, after the constructing the mapping relationship between the original code and the target code according to the creation information, to obtain the code mapping relationship, the method further comprises:

[0027] finding a test code in the code mapping relationship, specifically comprising:

[0028] receiving a code query request;

[0029] parsing the code query request to obtain query statement structure information;

[0030] According to the query statement structure information, the target code in the code mapping relationship is queried to obtain the test code, and the test code is displayed.

[0031] In some embodiments, the query statement structure information includes query time interval information, query user information, table query identification information, and code query identification information; and according to the query statement structure information, the target code in the code mapping relationship is queried to obtain the test code, and the test code is displayed, including:

[0032] According to the query time interval information and the creation time information, candidate code mapping relationships are filtered from the code mapping relationship;

[0033] According to the query user information and the conversion user information, selected code mapping relationships are filtered from the candidate code mapping relationships;

[0034] According to the table query identification information and the table creation identification information, target code mapping relationships are filtered from the selected code mapping relationships;

[0035] According to the code query identification information and the code creation identification information, the test code is filtered from the target code in the target code mapping relationship, and the test code is displayed.

[0036] To achieve the above object, a second aspect of the embodiment of the present application proposes a code conversion device, which comprises:

[0037] A code acquisition module is configured to acquire an original code; wherein the original code includes an original function statement and an original non-function statement;

[0038] A syntax acquisition module is configured to acquire original syntax information according to an original function name of the original function statement;

[0039] A difference comparison module is configured to compare the original syntax information with preset target syntax information to obtain to-be-converted syntax information;

[0040] A function acquisition module is configured to acquire function information of the original function statement according to the to-be-converted syntax information;

[0041] A filtering module is configured to filter a target function statement from preset candidate function mapping relationships according to the function information;

[0042] A splicing module is configured to splice the target function statement and the original non-function statement to obtain a target code.

[0043] To achieve the above object, a third aspect of the embodiment of the present application provides a computer device, comprising a memory and a processor, the memory stores a computer program, and the processor implements the method in the first aspect when executing the computer program.

[0044] To achieve the above object, a fourth aspect of the embodiment of the present application provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the method in the first aspect.

[0045] The code conversion method and device, computer device and storage medium provided by the present application can improve the efficiency of code conversion by setting a code conversion end between a code storage end and a data test end, obtaining an original code through the code conversion end, obtaining original syntax information of an original function statement in the original code, performing difference comparison on the original syntax information and target syntax information to obtain to-be-converted syntax information, obtaining function information of the original function statement according to the to-be-converted syntax information, screening a target function statement from a preset candidate function mapping relationship according to the function information, and splicing the original non-function statement in the original code and the target function statement to form a target code. BRIEF DESCRIPTION OF DRAWINGS

[0046] Figure 1 is a system architecture diagram of the code conversion method provided by the embodiment of the present application;

[0047] Figure 2 is a flowchart of the code conversion method provided by the embodiment of the present application;

[0048] Figure 3 is a flowchart of the code conversion method provided by another embodiment of the present application;

[0049] Figure 4 is Figure 2 a flowchart of step S205 in

[0050] Figure 5 is Figure 4 a flowchart of step S402 in

[0051] Figure 6 is a flowchart of the code conversion method provided by another embodiment of the present application;

[0052] Figure 7 is a flowchart of the code conversion method provided by another embodiment of the present application;

[0053] Figure 8 is Figure 7 a flowchart of step S703 in

[0054] Figure 9This is a schematic diagram of the structure of the code conversion device provided in the embodiments of this application;

[0055] Figure 10 This is a schematic diagram of the hardware structure of the computer device provided in the embodiments of this application. Detailed Implementation

[0056] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0057] It should be noted that although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first," "second," etc., in the specification, claims, and the aforementioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.

[0058] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.

[0059] First, let's analyze some of the terms used in this application:

[0060] Artificial intelligence (AI) is a new branch of computer science that studies, develops, and applies theories, methods, technologies, and systems to simulate, extend, and expand human intelligence. It aims to understand the essence of intelligence and produce intelligent machines that can react in a way similar to human intelligence. Research in this field includes robotics, speech recognition, image recognition, natural language processing, and expert systems. AI can simulate the information processes of human consciousness and thought. Furthermore, AI utilizes digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceiving the environment, acquiring knowledge, and using that knowledge to achieve optimal results.

[0061] Oracle Database: Oracle Database is a database management system with complete data management capabilities, comprehensive relational products, distributed processing capabilities, and the ability to implement data warehouse operations. As a general-purpose database system, Oracle Database offers complete data management functions.

[0062] Syntactic rules: Syntactic rules are the conventional rules governing abstract compositional and aggregational relations in a language. They can include compositional rules and aggregational rules, and can be used to express semantic relations. Compositional rules: Rules governing the linear combination of units of language structure. Aggregational rules: Rules governing the interchangeable arrangement of units with the same function at a specific position within a language structure.

[0063] Structured Query Language (SQL): SQL is a language for manipulating databases, including creating and deleting databases, querying and modifying records, and adding fields. Although SQL is a language standardized by ANSI, it has many different implementations. SQL can also be used to store, retrieve, and modify data stored in relational databases.

[0064] With the development of the big data era, the original code stored in the original database often needs to be converted before it can be executed on another data testing platform. However, each time the data testing platform retrieves the code stored in the original database and then converts it, and the code is converted manually before being tested by the data testing platform, the conversion process takes a lot of time, the code conversion efficiency is low, and thus affects the testing efficiency of the data testing platform.

[0065] Based on this, embodiments of this application provide a code conversion method and apparatus, computer equipment, and storage medium. By setting up a code conversion terminal between a code storage terminal and a data testing terminal, the original code is obtained through the code conversion terminal. Then, the original syntax information of the original function statements in the original code is obtained. The original syntax information and target syntax information are compared to obtain the syntax information to be converted. Based on the syntax information to be converted, the function information of the original function statements is obtained. Based on the function information, the target function statements are selected from a preset candidate function mapping relationship. This concatenates the original non-function statements and target function statements in the original code into target code, thereby improving the efficiency of code conversion. The original code is converted into target code that conforms to the syntax rules of the data testing terminal, so that the data testing terminal can directly call the target code for data testing, thereby improving data testing efficiency.

[0066] The code conversion method, apparatus, computer equipment, and storage medium provided in this application are specifically described through the following embodiments. First, the code conversion method in this application is described.

[0067] The embodiments of this application can acquire and process relevant data based on artificial intelligence technology. Artificial intelligence (AI) refers to the theories, methods, technologies, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to obtain optimal results.

[0068] Foundational technologies for artificial intelligence generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies mainly encompass computer vision, robotics, biometrics, speech processing, natural language processing, and machine learning / deep learning.

[0069] The code conversion method provided in this application relates to the field of artificial intelligence technology. The code conversion method provided in this application can be applied to a terminal, a server, or software running on either a terminal or a server. In some embodiments, the terminal can be a smartphone, tablet, laptop, desktop computer, etc.; the server can be configured as an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application implementing the code conversion method, but is not limited to the above forms.

[0070] This application can be used in a wide variety of general-purpose or special-purpose computer system environments or configurations. Examples include: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer computer devices, network PCs, minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices. This application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific tasks or implement specific abstract data types. This application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.

[0071] It should be noted that in all specific embodiments of this application, when processing data related to user identity or characteristics, such as user information, user behavior data, user historical data, and user location information, user permission or consent is obtained first. Furthermore, the collection, use, and processing of this data comply with relevant laws, regulations, and standards of the relevant countries and regions. In addition, when embodiments of this application require access to sensitive personal information of users, separate permission or consent from the user is obtained through pop-ups or redirects to confirmation pages. Only after obtaining the user's separate permission or consent is the necessary user-related data for the proper functioning of the embodiments of this application obtained.

[0072] Figure 1 This application illustrates the code conversion method provided in this embodiment, applied to a code conversion system architecture diagram. The code conversion system includes a code storage terminal, a code conversion terminal, and a data testing terminal, with the code storage terminal and the data testing terminal connected to the code conversion terminal. The code conversion terminal is built using Python and connects to the code storage terminal via a JDBC interface.

[0073] The code storage terminal is connected to the code conversion terminal. The code storage terminal is used to store the code. In this embodiment, the code storage terminal is equipped with an Oracle database to store the original code through the Oracle database.

[0074] The code conversion terminal communicates with both the code storage terminal and the data testing terminal. It retrieves the original code from the code storage terminal and then obtains the target syntax information from the data testing terminal. This allows it to compare the original syntax information of the original function statements in the original code with the target syntax information to obtain the syntax information to be converted. If the original syntax information differs from the target syntax information, the target function statement is selected from a pre-defined candidate function mapping relationship based on the function information of the original function statement. If the syntax information of the target function statement matches the target syntax information, the target function statement and the original non-function statements are concatenated to form the target code. Therefore, by pre-converting the original code in the code storage terminal to target code, the data testing terminal can directly obtain and execute the target code from the code conversion terminal, improving the efficiency of code conversion and thus improving the efficiency of data testing.

[0075] The data testing end communicates with the code conversion end and obtains the target code from the code conversion end. Then, it directly executes the target code to perform data testing, thereby improving the efficiency of data testing.

[0076] Figure 2 This is an optional flowchart of the code conversion method provided in the embodiments of this application. Figure 2The method may include, but is not limited to, steps S201 to S206.

[0077] Step S201: Obtain the original code; wherein, the original code includes: original function statements and original non-function statements;

[0078] Step S202: Obtain the original syntax information based on the original function name of the original function statement;

[0079] Step S203: Compare the original grammar information with the preset target grammar information to obtain the grammar information to be converted;

[0080] Step S204: Obtain the function information of the original function statement based on the syntax information to be converted;

[0081] Step S205: Select the target function statement from the preset candidate function mapping relationship based on the function information;

[0082] Step S206: Concatenate the target function statement and the original non-function statement to obtain the target code.

[0083] Steps S201 to S206 of this embodiment involve obtaining the original code, which includes original function statements and original non-function statements. The original syntax information is obtained based on the original function name. If the original syntax information differs from the target syntax information, a difference comparison is performed between the two to obtain the syntax information to be converted. The function information of the original function statements is then obtained based on this syntax information. Since the preset candidate mapping relationship includes target function statements that match the function information, the target function statement is selected from the preset candidate mapping relationship based on the function information. Finally, the target function statement and the original non-function statements are concatenated to obtain the target code. Therefore, by determining that the original syntax information and the target syntax information are different, the target function statement is selected from the candidate mapping relationship based on the function information, and the target function statement and the original non-function statements are concatenated to obtain the target code. This achieves automatic code conversion, generating target code that conforms to the target syntax information, improving the efficiency of the code conversion operation, and facilitating direct execution of the target code in the test environment corresponding to the target syntax information.

[0084] In step S201 of some embodiments, the original code can be obtained directly from the database of the code storage terminal, or it can be obtained in real time from the original code stored in the code storage terminal, and the acquisition of the original code is not limited to these two methods. The original code includes: original function statements and original non-function statements, and the original code is composed of original function statements and original non-function statements. Wherein, when the target syntax information and the original syntax information are different, the original function statements cannot be executed on the data test terminal corresponding to the target syntax information, so the original code cannot be executed directly, but the original non-function statements remain unchanged on the data test terminal. In this embodiment, the database of the code storage terminal is an Oracle database. Since the code stored in the Oracle database has been stored for a long time, it is difficult to be applicable to some data test terminals. Therefore, it is necessary to convert the original code in the Oracle database to obtain target code that conforms to the syntax of the data test terminal, so that the data test terminal can use it directly, thereby improving the efficiency of the data test terminal in performing data testing.

[0085] It should be noted that obtaining the original code includes at least one original function statement and at least one original non-function statement, and each original function statement and one original non-function statement are matched to form the original code segment. Therefore, the conversion of the original code mainly involves replacing or retaining each original code segment to obtain the target code.

[0086] In step S202 of some embodiments, the original function name of the original function statement is obtained, and the original syntax information is obtained based on the original function name to obtain the original syntax information matching the original function name. Here, the original syntax information refers to the original syntax rules, which are used to determine whether the original function statement needs to be transformed.

[0087] It should be noted that if the original code includes at least one original function statement, then the original syntax information of each original function statement is obtained so as to determine whether each original function statement needs to be transformed based on the original syntax information and the target syntax information.

[0088] In step S203 of some embodiments, if the original syntax information and the target syntax information are different, a difference comparison is performed between the original syntax information and the target syntax information to obtain the syntax information to be converted. The target syntax information is the syntax information that matches the original function name, which is the target syntax information corresponding to the original function name obtained at the data testing end. Each piece of original syntax information is compared with the matching target syntax information. If the original syntax information and the target syntax information are consistent, it means that the original function statement does not need to be converted. If the original syntax information and the target syntax information are different, a difference comparison is performed between the original syntax information and the target syntax information to obtain the syntax information to be converted. The syntax information to be converted represents the original function name of the original function statement, so that it is possible to know which original function statements in the original code need to be converted based on the syntax information to be converted.

[0089] In step S204 of some embodiments, since the syntax information to be converted indicates which original function statement in the original code needs to be converted, the function information of the corresponding original function statement is obtained based on the syntax information to be converted. The function information is used to characterize the category and function of the original function statement, so as to obtain the matching target function statement based on the function information.

[0090] In some embodiments, prior to step S205, the code conversion method further includes:

[0091] Construct a mapping relationship between candidate functions.

[0092] It should be noted that before selecting the target function statement from the candidate function mapping relationship based on the function information, it is necessary to first construct the candidate function mapping relationship, that is, to construct the mapping relationship between the original function statement and the candidate function statement. The candidate function statements in the candidate function mapping relationship must conform to the target syntax information, so as to select the target function statement that conforms to the target syntax information from the candidate function mapping relationship based on the function information.

[0093] Please see Figure 3 Construct candidate function mapping relationships, specifically including but not limited to steps S301 to S302:

[0094] Step S301: Obtain candidate function information for candidate function statements;

[0095] Step S302: Construct a mapping relationship between the original function statement and the candidate function statement based on the function information and the candidate function information to obtain the candidate function mapping relationship.

[0096] In step S301 of some embodiments, the candidate function statement is a function statement that conforms to the target syntax information. The candidate function information of the candidate function statement is obtained, that is, the candidate function information of each candidate function statement that conforms to the target syntax information is obtained, so as to construct a mapping relationship between the candidate function statements with the same function and the original function statement, so as to select the target function statement from the candidate function statements.

[0097] In step S302 of some embodiments, a mapping relationship between the original function statement and the candidate function statement is constructed based on the function function information and the candidate function information. That is, a mapping relationship is constructed between the original function statement and the candidate function statement whose function function information and candidate function information are consistent to obtain the candidate function mapping relationship.

[0098] It should be noted that if the function information is A, and the candidate function information is also A, and the original function statement corresponding to the function information A is Q, while the candidate function statement corresponding to the candidate function information A is T, then a mapping relationship between Q and T is constructed, and this mapping relationship is written into the candidate function mapping relationship.

[0099] In steps S301 to S302 of this embodiment, candidate function information for each candidate function is obtained, and a mapping relationship is constructed between the original function statement and the candidate function statement that correspond to the function function information and the candidate function information to obtain a candidate function mapping relationship. Therefore, by constructing a candidate function mapping relationship between the original function statement and the candidate function statement, the target function statement corresponding to the original function statement can be extracted from the candidate function mapping relationship to obtain a target function statement that conforms to the target syntax information.

[0100] Please see Figure 4 In some embodiments, the function information includes: function category and function functionality information; step S205 may include, but is not limited to, steps S401 to S402:

[0101] Step S401: Filter the mapping relationship from candidate function mapping relationships to target function based on function category; wherein, the target function mapping relationship includes at least one candidate function statement;

[0102] Step S402: Select the target function statement from the candidate function statements based on the function function information.

[0103] In step S401 of some embodiments, since at least two candidate function mapping relationships are set, and candidate function statements of the same function category are stored in the same candidate function mapping relationship, the candidate function statements are classified and stored. Therefore, when searching for candidate function statements, the target function mapping relationship is first filtered from the candidate function mapping relationship according to the function category, that is, the target function mapping relationship matching the function category is obtained.

[0104] It should be noted that the function categories include at least one of the following: judgment category, calculation category, operation category, transformation category, time category, and comparison category. Category labels are set on the candidate function mapping relationship to find matching category labels based on the function category, and then the corresponding candidate function mapping relationship is retrieved based on the category label to obtain the target mapping relationship.

[0105] In step S402 of some embodiments, since the target function mapping relationship includes at least one candidate function statement, the target function statement is selected from the candidate function statements according to the function function information to obtain the target function statement that conforms to the target syntax information.

[0106] It should be noted that if the original function statement is "‖" and its function information indicates a field concatenation function, but "‖" cannot be used for field concatenation in the data testing context, then the target function statement is selected as the `concat` function based on the function information. This means the target function statement can be used in the data testing context. Therefore, by selecting the target function statement from the candidate function statements based on its function information, a target function statement that can be used in the data testing context is obtained, thereby improving the testing efficiency of the data testing context.

[0107] In steps S401 to S402 of this embodiment, matching target function mapping relationships are filtered from candidate function mapping relationships based on function categories, and the target function mapping relationship includes at least one candidate function statement. Then, target function statements are filtered from candidate function statements based on function functionality information to obtain target function statements that conform to target syntax information. Therefore, by filtering out target function statements that conform to target syntax information, target code is obtained by concatenating the target function statement and the original non-function statement. The target code can then be directly executed on the data testing end to improve the efficiency of data testing on the data testing end.

[0108] Please see Figure 5 In some embodiments, step S402 may include, but is not limited to, steps S501 to S503:

[0109] Step S501: Select the chosen function statement from the candidate function statements based on the function function information;

[0110] Step S502: Determine the priority of the selected function statement according to the preset priority determination rules to obtain the function level;

[0111] Step S503: Filter the target function statement from the selected function statements according to the function level.

[0112] In step S501 of some embodiments, a selected function statement is filtered from candidate function statements based on function function information, and at least one selected function statement is selected. For example, if the function function information is A, three selected function statements are filtered from the candidate function statements, and the three selected function statements are x, y, and z respectively. However, only one target function statement is needed, so it is necessary to filter the three selected function statements to select the target function statement that meets the requirements.

[0113] In step S502 of some embodiments, if at least two selected function statements exist, the selected function statements are prioritized according to a preset priority determination rule to obtain the function level. The preset priority determination rule can either pre-classify candidate function statements by priority, or after filtering out selected function statements, obtain the statement information of the selected function statements, and then determine the function level based on the preset priority determination rule and the statement information. Therefore, selected function statements can be divided according to their function levels to obtain selected function statements that meet the function level requirements. For example, if the statement information includes: statement generation time and statement space occupied, and the priority determination rule is a scoring relationship table, then the matching score is found from the scoring relationship table based on the statement generation time and statement space occupied of the selected function. Then, the score of the selected function statement is calculated based on the score and a preset weight, and the function level is then divided according to the score.

[0114] In step S503 of some embodiments, the function level of each selected function statement is calculated, and the target function statement is selected from the selected function statements according to the function level. In this embodiment, the selected function statement with the highest function level is obtained as the target function statement, which simplifies the selection of the target function statement.

[0115] Specifically, if the selected function statements are x, y, and z, then the function level of selected function statement x is level two, the function level of selected function statement y is level three, and the function level of selected function statement z is level one. Since the function level is directly proportional to the priority of the selected function statements, the selected function statement y is determined as the target function level. Therefore, the operation of filtering the target function statement from the selected function statements by function level is simple.

[0116] In steps S501 to S503 illustrated in this embodiment, the selected function statements are screened out from the candidate function statements according to the function function information. If at least two selected function statements are screened out, the statement generation time and statement occupied space of the selected function statements are obtained, and then the function levels of each selected function statement are determined according to the preset priority determination rule, statement generation time, and statement occupied space, and the selected function statement with the highest function level is obtained as the target function statement. Therefore, the target function statement is screened out from the selected function statements according to the function level, making it easier to obtain the target function statement.

[0117] In step S206 of some embodiments, after the target function statement is screened out, the target function statement and the original non-function statement are concatenated to obtain the target statement. Specifically, if the original code includes at least two original function statements, the original non-function statement that needs to be replaced with the target function statement is screened out, the target function statement and the corresponding original non-function statement are concatenated into a target code segment, and then the corresponding original code segment in the original code is replaced with the target code segment, while the original code segment that does not need to be replaced by the original function statement is retained to obtain the target code. Therefore, by converting the original code into the target code that conforms to the target syntax information, when the data test end needs to perform a test, it only needs to directly obtain the target code and execute the target code to implement the data test, so as to improve the efficiency of the data test.

[0118] For example, if the original code uses the original function statement "date" to compare the date size, and the original code is "proc_date >= date '2021-12-31' and proc_date < date '2022-12-31'", but the original syntax information of the original function statement and the target syntax information are different, then the difference calculation is performed on the original syntax information and the target syntax information to obtain the待转换语法信息. The function information of the original function statement is obtained according to the待转换语法信息, and then the target function statement "unix_timestamp" is screened out from the candidate functions according to the function information. Then the target function statement and the original non-function statement are concatenated to obtain the target code, and the target code is "proc_date >= unix_timestamp('2021-12-31 00:00:00') and proc_date <= unix_timestamp('2022-12-31 00:00:00')".

[0119] Please refer to Figure 6 , in some embodiments, after step S206, the code conversion method may further include: constructing a code mapping relationship.

[0120] It should be noted that, in order to facilitate the data testing end to obtain the target code, after the original code is converted into the target code, a code mapping relationship is constructed so that the data testing end can directly filter out the target code from the code mapping relationship and directly execute the target code to achieve data testing, thereby improving the efficiency of data testing.

[0121] Constructing the code mapping relationship may include, but is not limited to, steps S601 to S602:

[0122] Step S601: Obtain the creation information of the target code; wherein, the creation information includes: creation time information, conversion user information, table creation identifier information and code creation identifier information;

[0123] Step S602: Construct a mapping relationship between the original code and the target code based on the creation information to obtain the code mapping relationship.

[0124] In step S601 of some embodiments, if the target code is uploaded by multiple users, the creation time information, conversion user information, table creation identifier information and code creation identifier information of the target code are obtained, so as to classify the target code and construct code mapping relationship based on the creation time information, conversion user information, table creation identifier information and code creation identifier information.

[0125] In step S602 of some embodiments, a code mapping relationship is obtained by constructing a mapping relationship between the original code and the target code based on the creation information. This allows the target code to be directly read out and displayed from the code mapping relationship. Instead of the data testing end converting the code before performing data testing, the target code can be directly extracted from the code mapping relationship to execute the target code and perform data testing, thereby improving the efficiency of data testing.

[0126] In steps S601 to S602 of this embodiment, the creation information of the target code is obtained, and a mapping relationship between the original code and the target code is constructed based on the creation information to obtain the code mapping relationship. Therefore, the target code can be directly read from the code mapping relationship based on the creation information. When the data testing end performs data testing, it only needs to read and display the target code from the code mapping relationship, without having to convert the original code into the target code, thus improving the efficiency of data testing.

[0127] Please see Figure 7 In some embodiments, after step S602, the code conversion method further includes:

[0128] Find the test code in the code mapping relationship.

[0129] It should be noted that after establishing the code mapping relationship, if the data testing end needs to obtain test code, it will search for the test code in the code mapping relationship and send the test code to the data testing end so that the data testing end can directly execute the test code to implement data testing without having to perform code conversion during data testing, thereby improving data testing efficiency.

[0130] Locating the test code in the code mapping relationship may include, but is not limited to, steps S701 to S703:

[0131] Step S701: Receive code query request;

[0132] Step S702: Parse the code query request to obtain the query statement structure information;

[0133] Step S703: Based on the query statement structure information, perform a code query on the target code in the code mapping relationship to obtain the test code and display the test code.

[0134] In step S701 of some embodiments, since a code mapping relationship is constructed after the original code is converted into target code, when the data testing end needs to perform data testing, the code conversion end receives a code query request from the data testing end to perform code query according to the code query request.

[0135] In step S702 of some embodiments, the code query request is parsed, that is, the content and source of the code query request are parsed to construct query statement structure information, so that the test code can be found from the code mapping relationship more quickly and accurately based on the query statement structure information.

[0136] In step S703 of some embodiments, the target code in the code mapping relationship is searched according to the query statement structure information to find the target code that matches the query statement structure information as the test code, and the test code is directly displayed after it is obtained. At the same time, the test code is sent to the data testing terminal, which directly reads the test code and executes it to perform data testing. There is no need to perform code conversion before data testing, which saves data testing time and improves data testing efficiency.

[0137] It should be noted that if the data testing end needs to compare the size of two dates, the code conversion end will find the test code "proc_date>=unix_timestamp('2021-12-31 00:00:00')and proc_date<=unix_timestamp('2022-12-31 00:00:00')" from the code mapping relationship based on the query statement structure information. The code conversion end will then display the target code and send it to the data testing end. The data testing end can directly execute the test code to compare the size of the two dates without having to convert it to test code in advance, thereby improving the efficiency of data testing.

[0138] In steps S701 to S703 of the embodiment, a code query request sent by the data testing terminal is obtained. The query request is then parsed for its source and content to obtain the query statement structure information. Based on this structure information, the test code is retrieved from the target code in the code mapping relationship and displayed and sent to the data testing terminal. Therefore, when the data testing terminal needs to perform data testing, no code conversion is required; the test code can be executed directly to achieve the data test, saving testing time and improving data testing efficiency.

[0139] Please see Figure 8 In some embodiments, the query statement structure information includes: query time interval information, query user information, table query identifier information, and code query identifier information; step S703 may include, but is not limited to, steps S801 to S804:

[0140] Step S801: Based on the query time interval information and creation time information, filter out candidate code mapping relationships from the code mapping relationships;

[0141] Step S802: Select the chosen code mapping relationship from the candidate code mapping relationships based on the queried user information and the converted user information;

[0142] Step S803: Based on the table query identification information and the table creation identification information, filter the target code mapping relationship from the selected code mapping relationship;

[0143] Step S804: Based on the code query identification information and code creation identification information, filter out the test code from the target code mapping relationship and display the test code.

[0144] In step S801 of some embodiments, since the code mapping relationship is obtained by constructing a mapping relationship between the original code and the target code based on the creation information, each code mapping relationship is provided with creation information, which includes: creation time information, conversion user information, table creation identifier information, and code creation identifier information. During code querying, candidate code mapping relationships need to be filtered from the code mapping relationships based on the query time interval information and the creation time information. That is, the code mapping relationships whose creation time corresponds to the creation time information falling within the query time interval information are obtained to obtain candidate mapping relationships. Since the number of stored code mapping relationships is huge, it is only necessary to find the code mapping relationships that match the creation time information based on the query time interval information to obtain candidate code mapping relationships. Therefore, it is not necessary to search for the target code for each code mapping relationship, saving time in the target code search.

[0145] In step S802 of some embodiments, since there are multiple candidate code mapping relationships, that is, multiple candidate code mapping relationships may exist within the same time interval, it is necessary to further filter the candidate code mapping relationships to select the selected code mapping relationship based on the queried user information and the converted user information. That is, to obtain the candidate code mapping relationships that match the queried user information and the converted user information to obtain the selected code mapping relationship. This further narrows down the scope of test code search and saves test code search time.

[0146] For example, if 20 candidate code mappings are obtained through filtering, and the converted user information for 4 of these candidate code mappings is user P1, for 6 candidate code mappings is user P2, for 5 candidate code mappings is user P3, for 3 candidate code mappings is user P4, and for 2 candidate code mappings is user P5, then if the query user information is user P3, then 5 of these candidate code mappings will be selected as the chosen code mappings.

[0147] In step S803 of some embodiments, if the same user creates multiple code mapping relationships within the same time interval, it is necessary to filter the target code mapping relationship from the selected code mapping relationships based on the table query identifier information and the table creation identifier information. Since the table creation identifier information is unique, the selected code mapping relationship that matches the table creation identifier information is obtained as the target code mapping relationship. Therefore, the target code search only needs to be performed within one target code mapping relationship, thereby saving the time of test code search and improving the efficiency of test code search.

[0148] In step S804 of some embodiments, since the target code mapping relationship includes at least one target code and each target code is provided with code creation identification information, the target code matching the code creation identification information is obtained according to the code query information as the test code, so that the test code search is fast and efficient.

[0149] In steps S801 to S804 of this embodiment, candidate code mapping relationships are first obtained by acquiring code mapping relationships that match the creation time information based on the query time interval. Then, selected code mapping relationships are obtained by acquiring candidate code mapping relationships that match the converted user information and the queried user information. Next, target code mapping relationships are obtained by acquiring selected code mapping relationships that match the table creation identifier information and the table query identifier information. Finally, target code that matches the code creation identifier information and the code query identifier information is found from the target code mapping relationships and used as test code. Therefore, by progressively filtering target code mapping relationships and then selecting target code that matches the code creation identifier information and the code query identifier information from the target code mapping relationships as test code, the time for finding target code is saved, thereby improving the efficiency of target code finding.

[0150] This application embodiment obtains the original code from the code storage terminal. The original code includes original function statements and original non-function statements. The original function names of the original function statements are obtained, and the original syntax information is obtained based on the original function names. If the original syntax information and the target syntax information are different, a difference comparison is performed between the original syntax information and the target syntax information to obtain the syntax information to be converted. Since the syntax information to be converted indicates which original function statement in the original code needs to be converted, the function information of the corresponding original function statement is obtained based on the syntax information to be converted. The function information includes: function category and function function information. Based on the function category, a target function mapping relationship is selected from the candidate function mapping relationship. The target function mapping relationship includes at least one candidate function statement. Based on the function function information, a selected function statement is selected from the candidate function statements, and the selected function statement is prioritized according to a preset priority determination rule to obtain the function level. The selected function statement with the highest function level is selected as the target function statement, making the selection of the target function statement simple. Finally, the target function statement and the original non-function statements are concatenated to obtain the target statement. After converting the original code into target code, a mapping relationship between the original code and the target code is constructed based on the creation information to obtain the code mapping relationship. When the data testing end needs to perform data testing, it receives code query requests from other data testing endpoints. These requests are parsed for content and source to construct the query statement structure, which includes: query time interval information, query user information, table query identifier information, and code query identifier information. First, candidate code mappings are obtained based on the query time interval and the code mappings matching the creation time information. Then, selected code mappings are obtained based on the candidate code mappings matching the converted user information and the query user information. Next, the target code mappings are obtained based on the selected code mappings matching the table creation identifier information and the table query identifier information. Finally, the target code matching the code creation identifier information and the code query identifier information is found from the target code mappings and used as the test code. Therefore, by converting the original code to target code before data testing on the data testing end, and ensuring that the target code is executable on the data testing end, the test code can be directly found from the code mappings and executed directly to perform data testing. This eliminates the need to convert the original code to target code beforehand, saving conversion time and improving data testing efficiency.

[0151] Please see Figure 9 This application also provides a code conversion apparatus that can implement the above-described code conversion method. The apparatus includes:

[0152] The code acquisition module 901 is used to acquire the original code; the original code includes: original function statements and original non-function statements;

[0153] The syntax acquisition module 902 is used to obtain the original syntax information based on the original function name of the original function statement;

[0154] The difference comparison module 903 is used to compare the original grammatical information with the preset target grammatical information to obtain the grammatical information to be converted.

[0155] The function acquisition module 904 is used to obtain the function information of the original function statement based on the syntax information to be converted;

[0156] The filtering module 905 is used to filter out target function statements from a preset candidate function mapping relationship based on function information;

[0157] The concatenation module 906 is used to concatenate the target function statement and the original non-function statement to obtain the target code.

[0158] The specific implementation of this code conversion device is basically the same as the specific implementation of the code conversion method described above, and will not be repeated here.

[0159] This application also provides a computer device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the above-described code conversion method. This computer device can be any smart terminal, including tablet computers, in-vehicle computers, etc.

[0160] Please see Figure 10 , Figure 10 The hardware structure of a computer device according to another embodiment is illustrated. The computer device includes:

[0161] The processor 1001 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application.

[0162] The memory 1002 can be implemented as a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 1002 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 1002 and is called and executed by the processor 1001 using the code conversion method of the embodiments of this application.

[0163] Input / output interface 1003 is used to implement information input and output;

[0164] The communication interface 1004 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).

[0165] Bus 1005 transmits information between various components of the device (e.g., processor 1001, memory 1002, input / output interface 1003, and communication interface 1004);

[0166] The processor 1001, memory 1002, input / output interface 1003 and communication interface 1004 are connected to each other within the device via bus 1005.

[0167] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described code conversion method.

[0168] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.

[0169] The code conversion method, apparatus, computer device, and storage medium provided in this application embodiment obtain the syntax information to be converted by comparing the original syntax information and the target syntax information. Then, the function information of the original function statement is obtained based on the syntax information to be converted. The target function statement is then selected from the candidate mapping relationship based on the function information. The target function statement and the original non-function statement are concatenated to obtain the target code, thereby realizing automatic code conversion and generating target code that conforms to the target syntax information. This improves the efficiency of the code conversion operation, and the converted target code can be directly used for data testing, thereby improving the efficiency of data testing.

[0170] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.

[0171] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.

[0172] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0173] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.

[0174] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0175] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: 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.

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

[0177] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0178] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0179] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0180] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the claims of the present application.

Claims

1. A code conversion method, characterized in that, The method includes: Obtain the original code; wherein the original code includes: original function statements and original non-function statements; Obtain the original syntax information based on the original function name of the original function statement; The original grammar information and the preset target grammar information are compared to obtain the grammar information to be converted. The function information of the original function statement is obtained based on the syntax information to be converted; The target function statement is selected from the preset candidate function mapping relationship based on the function information; The target function statement and the original non-function statement are concatenated to obtain the target code; the function information includes: function category and function functionality information; the step of filtering the target function statement from a preset candidate function mapping relationship based on the function information includes: Based on the function category, a target function mapping relationship is selected from the candidate function mapping relationships; wherein, the target function mapping relationship includes at least one candidate function statement; The target function statement is selected from the candidate function statements based on the function functionality information; Obtain the creation information of the target code; wherein, the creation information includes: creation time information, conversion user information, table creation identifier information, and code creation identifier information; Based on the creation information, a mapping relationship is constructed between the original code and the target code to obtain the code mapping relationship.

2. The method according to claim 1, characterized in that, The step of filtering the target function statement from the candidate function statements based on the function functionality information includes: Selected function statements are selected from the candidate function statements based on the function functionality information; The selected function statement is prioritized according to a preset priority determination rule to obtain the function level; The target function statement is selected from the selected function statements based on the function level.

3. The method according to claim 1, characterized in that, Before selecting the target function statement from the preset candidate function mapping relationship based on the function information, the method further includes: Constructing the candidate function mapping relationship specifically includes: Obtain the candidate function information of the candidate function statement; Based on the function information and the candidate function information, a mapping relationship is constructed between the original function statement and the candidate function statement to obtain the candidate function mapping relationship.

4. The method according to any one of claims 1 to 3, characterized in that, After constructing the mapping relationship between the original code and the target code based on the creation information to obtain the code mapping relationship, the method further includes: Finding the test code within the code mapping relationship specifically includes: Receive code query requests; The code query request is parsed to obtain the query statement structure information; Based on the query statement structure information, the target code in the code mapping relationship is queried to obtain the test code, and the test code is displayed.

5. The method according to claim 4, characterized in that, The query statement structure information includes: query time interval information, query user information, table query identifier information, and code query identifier information; the step of performing code query on the target code in the code mapping relationship according to the query statement structure to obtain the test code and display the test code includes: Based on the query time interval information and the creation time information, candidate code mapping relationships are filtered from the code mapping relationships; Based on the queried user information and the converted user information, the selected code mapping relationship is filtered from the candidate code mapping relationship; Based on the identification information queried from the table and the identification information created from the table, the target code mapping relationship is filtered out from the selected code mapping relationship; The test code is selected from the target code in the target code mapping relationship based on the code query identification information and the code creation identification information, and then the test code is displayed.

6. A code conversion device, characterized in that, The device includes: The code acquisition module is used to acquire the original code; wherein, the original code includes: original function statements and original non-function statements; The syntax acquisition module is used to obtain the original syntax information based on the original function name of the original function statement; The difference comparison module is used to compare the original grammatical information with the preset target grammatical information to obtain the grammatical information to be converted. The function acquisition module is used to obtain the function information of the original function statement based on the syntax information to be converted; The filtering module is used to filter out target function statements from a preset candidate function mapping relationship based on the function information; The concatenation module is used to concatenate the target function statement and the original non-function statement to obtain the target code; The function information includes: function category and function functionality information; the step of filtering the target function statement from the preset candidate function mapping relationship based on the function information includes: Based on the function category, a target function mapping relationship is selected from the candidate function mapping relationships; wherein, the target function mapping relationship includes at least one candidate function statement; The target function statement is selected from the candidate function statements based on the function functionality information; Obtain the creation information of the target code; wherein, the creation information includes: creation time information, conversion user information, table creation identifier information, and code creation identifier information; Based on the creation information, a mapping relationship is constructed between the original code and the target code to obtain the code mapping relationship.

7. A computer device, characterized in that, The computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the code conversion method according to any one of claims 1 to 5.

8. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the code conversion method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Code conversion method and apparatus, computer storage medium and code conversion terminal

    CN108595184A

  • Application program code conversion method and device, electronic equipment and storage medium

    CN111708539A