CN112363727A - JAVA conversion method and device of SQL (structured query language) code, computer equipment and storage medium - Google Patents

JAVA conversion method and device of SQL (structured query language) code, computer equipment and storage medium Download PDF

Info

Publication number
CN112363727A
CN112363727A CN202011244905.5A CN202011244905A CN112363727A CN 112363727 A CN112363727 A CN 112363727A CN 202011244905 A CN202011244905 A CN 202011244905A CN 112363727 A CN112363727 A CN 112363727A
Authority
CN
China
Prior art keywords
java
sql
fine
lexical analysis
context information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202011244905.5A
Other languages
Chinese (zh)
Inventor
周毅
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Life Insurance Company of China Ltd
Original Assignee
Ping An Life Insurance Company of China Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Life Insurance Company of China Ltd filed Critical Ping An Life Insurance Company of China Ltd
Priority to CN202011244905.5A priority Critical patent/CN112363727A/en
Publication of CN112363727A publication Critical patent/CN112363727A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/425Lexical analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/35Creation or generation of source code model driven

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • General Physics & Mathematics (AREA)
  • Mathematical Physics (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The invention discloses a JAVA conversion method and device of SQL codes, computer equipment and a storage medium, which relate to the big data technology and comprise the steps of obtaining SQL sentences to be converted, and carrying out lexical analysis on the SQL sentences to be converted according to a called first regular expression set to obtain lexical analysis results; carrying out syntactic analysis on the lexical analysis result to obtain a corresponding abstract syntactic tree; performing semantic analysis on the abstract syntax tree to obtain context information; performing Java grammar conversion on the lexical analysis result and the context information to obtain a fine-tuned syntax tree and fine-tuned context information; and calling a pre-stored code template, and filling the fine-tuned syntax tree and the fine-tuned context information into the code template to obtain a target Java code. The method realizes the automatic conversion of the SQL statement into the executable Java code without manual adjustment, improves the conversion efficiency and reduces the conversion error rate.

Description

JAVA conversion method and device of SQL (structured query language) code, computer equipment and storage medium
Technical Field
The invention relates to the technical field of data storage of big data, in particular to a JAVA conversion method and device of SQL (structured query language) codes, computer equipment and a storage medium.
Background
Currently, Oracle is often used as a database in a data storage scenario, a small computer is required to be used as hardware, and PL/SQL is required to be used as a programming language for coding. The following disadvantages exist when using an Oracle database to store data:
1) oracle is a commercial closed-source product, strongly depends on manufacturer service, and cannot be mastered by the bottom layer technology;
2) the software and hardware are strongly bound, the cost is increased year by year, and the cost is uncontrollable;
3) the technology is disjointed from the mainstream internet technology, and the learning cost is high;
4) particularly, in the context of mass data calculation, the calculation needs to be completed in a short time due to the mass data size and the very complex calculation logic. The use of Oracle has the problem that the horizontal expansion cannot be realized, so that the time consumption of mass data calculation is increased step by step.
Disclosure of Invention
The embodiment of the invention provides a JAVA conversion method, a JAVA conversion device, computer equipment and a storage medium of SQL codes, and aims to solve the problems that when SQL sentences in an Oracle database are migrated to other platforms in the prior art, massive and complex SQL sentences need to be manually converted into sentences of other languages, the efficiency is low, and conversion errors are easy to occur.
In a first aspect, an embodiment of the present invention provides a JAVA conversion method for SQL codes, which includes:
acquiring an SQL sentence to be converted, and carrying out lexical analysis on the SQL sentence to be converted according to the called first regular expression set to obtain a lexical analysis result;
carrying out syntactic analysis on the lexical analysis result to obtain a corresponding abstract syntactic tree;
performing semantic analysis on the abstract syntax tree to obtain context information;
performing Java grammar conversion on the lexical analysis result and the context information to obtain a fine-tuned syntax tree and fine-tuned context information; and
and calling a pre-stored code template, and filling the fine-tuned syntax tree and the fine-tuned context information into the code template to obtain a target Java code.
In a second aspect, an embodiment of the present invention provides a JAVA conversion apparatus for SQL codes, which includes:
the lexical analysis unit is used for acquiring the SQL sentences to be converted, and carrying out lexical analysis on the SQL sentences to be converted according to the called first regular expression set to obtain lexical analysis results;
the syntactic analysis unit is used for carrying out syntactic analysis on the lexical analysis result to obtain a corresponding abstract syntactic tree;
the semantic analysis unit is used for performing semantic analysis on the abstract syntax tree to obtain context information;
performing Java grammar conversion on the lexical analysis result and the context information to obtain a fine-tuned syntax tree and fine-tuned context information; and
and the code fine-tuning filling unit is used for calling a pre-stored code template, and filling the fine-tuned syntax tree and the fine-tuned context information into the code template to obtain the target Java code.
In a third aspect, an embodiment of the present invention further provides a computer device, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor, where the processor implements the JAVA conversion method for SQL codes according to the first aspect when executing the computer program.
In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and the computer program, when executed by a processor, causes the processor to execute the JAVA conversion method for SQL codes according to the first aspect.
The embodiment of the invention provides a JAVA conversion method, a JAVA conversion device, computer equipment and a storage medium of SQL codes, wherein the JAVA conversion method comprises the steps of obtaining SQL sentences to be converted, and carrying out lexical analysis on the SQL sentences to be converted according to a called first regular expression set to obtain lexical analysis results; carrying out syntactic analysis on the lexical analysis result to obtain a corresponding abstract syntactic tree; performing semantic analysis on the abstract syntax tree to obtain context information; performing Java grammar conversion on the lexical analysis result and the context information to obtain a fine-tuned syntax tree and fine-tuned context information; and calling a pre-stored code template, and filling the fine-tuned syntax tree and the fine-tuned context information into the code template to obtain a target Java code. The method realizes the automatic conversion of the SQL statement into the executable Java code without manual adjustment, improves the conversion efficiency and reduces the conversion error rate.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic view of an application scenario of a JAVA conversion method for SQL codes according to an embodiment of the present invention;
fig. 2 is a schematic flowchart of a JAVA conversion method of SQL codes according to an embodiment of the present invention;
fig. 3 is a schematic diagram of an abstract syntax tree in the JAVA conversion method of SQL codes according to an embodiment of the present invention;
fig. 4 is a schematic block diagram of a JAVA conversion apparatus for SQL codes according to an embodiment of the present invention;
FIG. 5 is a schematic block diagram of a computer device provided by an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It will be understood that the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It is also to be understood that the terminology used in the description of the invention herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in the specification of the present invention and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
It should be further understood that the term "and/or" as used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
Referring to fig. 1 and fig. 2, fig. 1 is a schematic view of an application scenario of a JAVA conversion method for SQL codes according to an embodiment of the present invention; fig. 2 is a schematic flow chart of a JAVA conversion method for an SQL code according to an embodiment of the present invention, where the JAVA conversion method for the SQL code is applied to a server, and the method is executed by application software installed in the server.
As shown in fig. 2, the method includes steps S110 to S150.
S110, if a preparation message sent by an application instance embedded with an ignition program JAR packet is detected, acquiring a local lock type; wherein the lock types include pessimistic locks and optimistic locks.
In this embodiment, in order to convert the pl \ SQL code used in the Oracle database into JAVA code (for example, in the present application, the SQL statement is converted into JAVA code), a series of data processing such as lexical analysis and syntactic analysis is required.
When the SQL sentence to be converted is converted into the Java code, lexical analysis is firstly required. The lexical analysis can use a lexical analyzer, the input of the lexical analyzer is a character stream corresponding to the SQL sentence to be converted, the output of the lexical analyzer is a morpheme sequence, and a lexical unit (token) is generated for each morpheme. The form that morphemes of lexical units may have is described by a pattern (pattern), and the pattern is represented by a regular expression (the regular expression in the present application is a regular expression having only a character string matching capability).
In one embodiment, step S110 includes:
converting the called first regular expression set into a non-deterministic finite state automaton through the called Topson algorithm;
converting the non-deterministic finite state automaton into a deterministic finite state machine by a subset construction method;
simplifying the determined finite state machine into a minimum state determined finite state machine through a segmentation method to obtain a conversion table corresponding to the minimum state determined finite state machine;
calling a preset finite state machine simulator to form a lexical analyzer together with the conversion table;
and inputting the SQL sentence to be converted into the lexical analyzer to obtain a lexical analysis result through conversion.
In the present embodiment, the non-Deterministic Finite state automaton refers to (NFA is a short hand for non-Deterministic Finite Automation), and the Deterministic Finite state machine refers to DFA (DFA is a short hand for Deterministic Finite Automation).
Wherein the Thompson algorithm (i.e., Thompson algorithm) is used to convert regular expressions into NFAs. The two basic transformations most commonly used in the thompson algorithm are: normal conversion (to convert an input character to another state) and epsilon conversion (to convert only one state to another without input).
And after the non-deterministic finite state automaton is obtained, converting the NFA into the DFA by a subset structuring method in a compiling principle. The basic idea of the subset construction method is to make each state of the constructed DFA correspond to a state set of the NFA.
Finally, when the definite finite-state machine is simplified into the minimum state definite finite-state machine by the segmentation method, redundant states (redundant states mean that the state has no path to reach the final state) in the definite finite-state machine are deleted, so that the definite finite-state machine is simplified into the minimum state definite finite-state machine.
After NFA conversion, DFA conversion and NFA simplification, a conversion table is obtained correspondingly, and the conversion table and a fixed DFA simulator are added to form the lexical analyzer.
For example, the lexical analysis process of the source program 1+2 × 3 is as follows:
the digit morphemes 1, 2, and 3 may be matched by digit patterns (i.e., regular expressions used to match numeric characters) in the first regular expression set, and the operator morphemes + and may be matched by operator patterns (i.e., regular expressions used to match operator characters) in the first regular expression set. Finally, each morpheme generates lexical units (tokens) to form lexical analysis results.
More specifically, the SQL statement select ID from idiinfo gets 4 tokens after lexical analysis, where tokens include keywords and non-keywords, selects and from are two of the keywords, and ID and idiinfo are two of the non-keywords.
And S120, carrying out syntactic analysis on the lexical analysis result to obtain a corresponding abstract syntax tree.
In this embodiment, the syntax analysis is a process of matching a sentence conforming to Java language syntax in a lexical unit (token) stream corresponding to a result of the lexical analysis, that is, generating a syntax tree according to the result of the lexical analysis.
In one embodiment, step S120 includes:
and carrying out syntactic analysis on the lexical analysis result through a Bison syntactic analyzer to obtain a corresponding abstract syntactic tree.
That is, when the syntax analysis is performed on the lexical analysis result corresponding to the SQL statement, a Bison syntax analyzer may be used, so as to obtain a corresponding abstract syntax tree.
For example, there are SQL statements: select username, isfemale from userinfo where 18andheight 175, generates an abstract syntax tree as shown in FIG. 3.
In the SQL statement, a Keyword in a corresponding morpheme (token) has a select, a from, a where and conditions, a non-Keyword has a user name, an isfemale, a userinfo, an age, 18, a height, and 175, where the userinfo corresponds to table information, the age, 18, the height, and 175 correspond to item lists, and the useriname and the isfemale correspond to area information, and the list information in the Bison parser is filled with the information obtained by analysis, so that an abstract syntax tree can be obtained.
In an embodiment, the step of performing syntax analysis on the lexical analysis result by using a Bison syntax analyzer to obtain a corresponding abstract syntax tree includes:
acquiring list information in a Bison grammar analyzer; the list information comprises a table list, an order list and an item list;
storing table information in the lexical analysis result in a table list, storing information in order clauses in the lexical analysis result in an order list, and storing information in where clauses in an item list;
and correspondingly acquiring the abstract syntax tree according to the list information of the currently stored data.
In this embodiment, since the code of C + + is embedded in the Bison parser (various objects are newly created in the code of C + +), information in the lexical analysis result can be stored in the related objects by using the code. Specifically, table information in the lexical analysis result is stored in a table list, information in an orderby clause in the lexical analysis result is stored in the order list, and information in a where clause is stored in an item list, so that the abstract syntax tree is obtained.
S130, performing semantic analysis on the abstract syntax tree to obtain context information.
In this embodiment, after the abstract syntax tree of the SQL statement is obtained through syntax analysis, the corresponding context information needs to be obtained through semantic analysis. After the abstract syntax tree is generated, the abstract syntax tree is analyzed, the process is called semantic analysis, and at this step, the resolution of variable references, the resolution of type names, the type definition check, the validity check of expressions and the static type check are needed to be performed. The semantic analysis is performed in sequence according to the listed processing procedures.
In one embodiment, step S130 includes:
and sequentially carrying out variable reference resolution, type name resolution, type definition check, expression validity check and static type check on the abstract syntax tree to obtain context information.
The resolution of variable references refers to associating all variables with their definitions, for example, the variable a may be a global variable a, a static variable a, or a local variable a, and in order to eliminate the uncertainty, we associate the variables with the definitions. The specific operation is to add the attribute of the variable definition to the variable node object.
The Type name resolution is because in some languages, the Type name Type and the Type entity Type are processed separately, because the Type name Type can be understood as a declaration of the Type, and the Type is an implementation of the Type, and the user may use the Type before the implementation, so that the processing is differentiated. The resolution of the Type name here is to associate Type ref with Type and manage the correspondence relationship between them by an object of Type table.
The type definition checking is to check that definition declarations that do not conform to the logic are used when defining the type, such as 1) arrays, structures, complexes that contain void; 2) a structure, complex of member repetitions; 3) structure, complex defined by a cycle.
The validity check of the expression requires detection of the problems: assigning values to expressions which cannot be assigned (example: 1: 2+2), calling functions by illegal function names (example: string (% d \ n ", i)), array reference with illegal operands (example: 1[0]), member reference with illegal operands (example: 1.memb), pointer indirect reference with illegal operands (example: 1- > memb), taking values to objects without pointers (example: 1:), and taking addresses to expressions with non-left values.
For example, addition cannot be performed between structures, multiplication cannot be performed between pointers and values, and abnormal results occur when an array is transferred to a function with a parameter type of int. Restrictions are placed on the types of operands allowed, e.g., operations only apply between values of the same type, and the process of checking for compliance with such restrictions during compilation is static type checking.
S140, performing Java grammar conversion on the lexical analysis result and the context information to obtain a fine-tuned syntax tree and fine-tuned context information.
In the embodiment, the generated abstract syntax tree and context information are converted into a syntax tree and context that can adapt to the grammar corresponding to the Java code. For example, Java grammar conversion type representation, loop statement conversion, and the like are performed.
In one embodiment, step S140 includes:
and obtaining the lexical analysis result and the type representation and the cycle statement in the context information, and converting the type representation and the cycle statement into Java type representation and Java cycle statement under a Java grammar so as to obtain a fine-tuned syntax tree and fine-tuned context information.
In this embodiment, the lexical analysis result and the type expression and the loop statement (e.g., for statement, while statement, loop statement, etc.) in the context information are obtained first, and since the type expressions are grammars applicable to the PL/SQL language in the Oracle database and are not applicable to the Java grammar, the type expressions and the loop statements are converted into Java type expressions and Java loop statements in the Java grammar, so that the fine-tuned syntax tree and the fine-tuned context information can be obtained.
S150, calling a pre-stored code template, and filling the fine-tuned syntax tree and the fine-tuned context information into the code template to obtain a target Java code.
In this embodiment, a code template provided by a template engine is added with a technical platform related code supporting Java language, and the fine-tuned syntax tree and the fine-tuned context information are filled in the code template to obtain a target Java code, where the target Java code is a code that can be run on a technical platform.
Therefore, the SQL statements are converted into executable Java codes, and the executable Java codes can be directly operated on a technical platform after the conversion is finished without manual adjustment. And the syntax tree and the context information are stored in a database local to the technical platform, so that the understanding, the tracking and the maintenance of the tool are convenient.
In an embodiment, step S150 is followed by:
the built-in functions of the Oracle database are obtained to register locally.
In this embodiment, in order to increase the adaptability of the technical platform, the built-in function of Oracle is implemented and registered in the technical platform, so that the converted standard SQL can also support the built-in function of Oracle.
The method realizes the automatic conversion of the SQL statement into the executable Java code without manual adjustment, improves the conversion efficiency and reduces the conversion error rate.
The embodiment of the invention also provides a JAVA conversion device of the SQL code, which is used for executing any embodiment of the JAVA conversion method of the SQL code. Specifically, referring to fig. 4, fig. 4 is a schematic block diagram of a JAVA conversion apparatus for SQL codes according to an embodiment of the present invention. The JAVA conversion apparatus 100 of the SQL code may be configured in a server.
As shown in fig. 4, the JAVA conversion apparatus 100 of SQL codes includes: a lexical analysis unit 110, a syntax analysis unit 120, a semantic analysis unit 130, a fine tuning unit 140, and a code filling unit 150.
The lexical analysis unit is used for acquiring a local lock type if a preparation message sent by an application instance embedded with an ignition program JAR packet is detected; wherein the lock types include pessimistic locks and optimistic locks.
In this embodiment, in order to convert the pl \ SQL code used in the Oracle database into JAVA code (for example, in the present application, the SQL statement is converted into JAVA code), a series of data processing such as lexical analysis and syntactic analysis is required.
When the SQL sentence to be converted is converted into the Java code, lexical analysis is firstly required. The lexical analysis can use a lexical analyzer, the input of the lexical analyzer is a character stream corresponding to the SQL sentence to be converted, the output of the lexical analyzer is a morpheme sequence, and a lexical unit (token) is generated for each morpheme. The form that morphemes of lexical units may have is described by a pattern (pattern), and the pattern is represented by a regular expression (the regular expression in the present application is a regular expression having only a character string matching capability).
In one embodiment, the lexical analysis unit 110 includes:
the first conversion unit is used for converting the called first regular expression set into the non-deterministic finite state automata through the called Topson algorithm;
the second conversion unit is used for converting the non-deterministic finite state automaton into the deterministic finite state machine by a subset construction method;
a third conversion unit, configured to simplify the deterministic finite state machine into a minimal state deterministic finite state machine by a segmentation method, so as to obtain a conversion table corresponding to the minimal state deterministic finite state machine;
the lexical analyzer obtaining unit is used for calling a preset finite state machine simulator to form a lexical analyzer together with the conversion table;
and the lexical analysis and conversion unit is used for inputting the SQL sentence to be converted into the lexical analyzer so as to obtain a lexical analysis result through conversion.
In the present embodiment, the non-Deterministic Finite state automaton refers to (NFA is a short hand for non-Deterministic Finite Automation), and the Deterministic Finite state machine refers to DFA (DFA is a short hand for Deterministic Finite Automation).
Wherein the Thompson algorithm (i.e., Thompson algorithm) is used to convert regular expressions into NFAs. The two basic transformations most commonly used in the thompson algorithm are: normal conversion (to convert an input character to another state) and epsilon conversion (to convert only one state to another without input).
And after the non-deterministic finite state automaton is obtained, converting the NFA into the DFA by a subset structuring method in a compiling principle. The basic idea of the subset construction method is to make each state of the constructed DFA correspond to a state set of the NFA.
Finally, when the definite finite-state machine is simplified into the minimum state definite finite-state machine by the segmentation method, redundant states (redundant states mean that the state has no path to reach the final state) in the definite finite-state machine are deleted, so that the definite finite-state machine is simplified into the minimum state definite finite-state machine.
After NFA conversion, DFA conversion and NFA simplification, a conversion table is obtained correspondingly, and the conversion table and a fixed DFA simulator are added to form the lexical analyzer.
For example, the lexical analysis process of the source program 1+2 × 3 is as follows:
the digit morphemes 1, 2, and 3 may be matched by digit patterns (i.e., regular expressions used to match numeric characters) in the first regular expression set, and the operator morphemes + and may be matched by operator patterns (i.e., regular expressions used to match operator characters) in the first regular expression set. Finally, each morpheme generates lexical units (tokens) to form lexical analysis results.
More specifically, the SQL statement select ID from idiinfo gets 4 tokens after lexical analysis, where tokens include keywords and non-keywords, selects and from are two of the keywords, and ID and idiinfo are two of the non-keywords.
And a syntax analysis unit 120, configured to perform syntax analysis on the lexical analysis result to obtain a corresponding abstract syntax tree.
In this embodiment, the syntax analysis is a process of matching a sentence conforming to Java language syntax in a lexical unit (token) stream corresponding to a result of the lexical analysis, that is, generating a syntax tree according to the result of the lexical analysis.
In an embodiment, the parsing unit 120 is further configured to:
and carrying out syntactic analysis on the lexical analysis result through a Bison syntactic analyzer to obtain a corresponding abstract syntactic tree.
That is, when the syntax analysis is performed on the lexical analysis result corresponding to the SQL statement, a Bison syntax analyzer may be used, so as to obtain a corresponding abstract syntax tree.
For example, there are SQL statements: select username, isfemale from userinfo where 18andheight 175, generates an abstract syntax tree as shown in FIG. 3.
In the SQL statement, a Keyword in a corresponding morpheme (token) has a select, a from, a where and conditions, a non-Keyword has a user name, an isfemale, a userinfo, an age, 18, a height, and 175, where the userinfo corresponds to table information, the age, 18, the height, and 175 correspond to item lists, and the useriname and the isfemale correspond to area information, and the list information in the Bison parser is filled with the information obtained by analysis, so that an abstract syntax tree can be obtained.
In one embodiment, the syntax analysis unit 120 includes:
the list information acquisition unit is used for acquiring the list information in the Bison parser; the list information comprises a table list, an order list and an item list;
the table data filling unit is used for storing table information in the lexical analysis result in a table list, storing information in order clauses in the lexical analysis result in the order list, and storing information in where clauses in the item list;
and the list information analysis unit is used for correspondingly acquiring the abstract syntax tree according to the list information of the currently stored data.
In this embodiment, since the code of C + + is embedded in the Bison parser (various objects are newly created in the code of C + +), information in the lexical analysis result can be stored in the related objects by using the code. Specifically, table information in the lexical analysis result is stored in a table list, information in an orderby clause in the lexical analysis result is stored in the order list, and information in a where clause is stored in an item list, so that the abstract syntax tree is obtained.
And the semantic analysis unit 130 is configured to perform semantic analysis on the abstract syntax tree to obtain context information.
In this embodiment, after the abstract syntax tree of the SQL statement is obtained through syntax analysis, the corresponding context information needs to be obtained through semantic analysis. After the abstract syntax tree is generated, the abstract syntax tree is analyzed, the process is called semantic analysis, and at this step, the resolution of variable references, the resolution of type names, the type definition check, the validity check of expressions and the static type check are needed to be performed. The semantic analysis is performed in sequence according to the listed processing procedures.
In an embodiment, the semantic analysis unit 130 is further configured to:
and sequentially carrying out variable reference resolution, type name resolution, type definition check, expression validity check and static type check on the abstract syntax tree to obtain context information.
The resolution of variable references refers to associating all variables with their definitions, for example, the variable a may be a global variable a, a static variable a, or a local variable a, and in order to eliminate the uncertainty, we associate the variables with the definitions. The specific operation is to add the attribute of the variable definition to the variable node object.
The Type name resolution is because in some languages, the Type name Type and the Type entity Type are processed separately, because the Type name Type can be understood as a declaration of the Type, and the Type is an implementation of the Type, and the user may use the Type before the implementation, so that the processing is differentiated. The resolution of the Type name here is to associate Type ref with Type and manage the correspondence relationship between them by an object of Type table.
The type definition checking is to check that definition declarations that do not conform to the logic are used when defining the type, such as 1) arrays, structures, complexes that contain void; 2) a structure, complex of member repetitions; 3) structure, complex defined by a cycle.
The validity check of the expression requires detection of the problems: assigning values to expressions which cannot be assigned (example: 1: 2+2), calling functions by illegal function names (example: string (% d \ n ", i)), array reference with illegal operands (example: 1[0]), member reference with illegal operands (example: 1.memb), pointer indirect reference with illegal operands (example: 1- > memb), taking values to objects without pointers (example: 1:), and taking addresses to expressions with non-left values.
For example, addition cannot be performed between structures, multiplication cannot be performed between pointers and values, and abnormal results occur when an array is transferred to a function with a parameter type of int. Restrictions are placed on the types of operands allowed, e.g., operations only apply between values of the same type, and the process of checking for compliance with such restrictions during compilation is static type checking.
And the fine-tuning unit 140 is configured to perform Java grammar conversion on the lexical analysis result and the context information to obtain a fine-tuned syntax tree and fine-tuned context information.
In the embodiment, the generated abstract syntax tree and context information are converted into a syntax tree and context that can adapt to the grammar corresponding to the Java code. For example, Java grammar conversion type representation, loop statement conversion, and the like are performed.
In an embodiment, the fine tuning unit 140 is further configured to:
and obtaining the lexical analysis result and the type representation and the cycle statement in the context information, and converting the type representation and the cycle statement into Java type representation and Java cycle statement under a Java grammar so as to obtain a fine-tuned syntax tree and fine-tuned context information.
In this embodiment, the lexical analysis result and the type expression and the loop statement (e.g., for statement, while statement, loop statement, etc.) in the context information are obtained first, and since the type expressions are grammars applicable to the PL/SQL language in the Oracle database and are not applicable to the Java grammar, the type expressions and the loop statements are converted into Java type expressions and Java loop statements in the Java grammar, so that the fine-tuned syntax tree and the fine-tuned context information can be obtained.
And a code filling unit 150, configured to call a pre-stored code template, and fill the fine-tuned syntax tree and the fine-tuned context information into the code template to obtain a target Java code.
In this embodiment, a code template provided by a template engine is added with a technical platform related code supporting Java language, and the fine-tuned syntax tree and the fine-tuned context information are filled in the code template to obtain a target Java code, where the target Java code is a code that can be run on a technical platform.
Therefore, the SQL statements are converted into executable Java codes, and the executable Java codes can be directly operated on a technical platform after the conversion is finished without manual adjustment. And the syntax tree and the context information are stored in a database local to the technical platform, so that the understanding, the tracking and the maintenance of the tool are convenient.
In one embodiment, the apparatus 100 for JAVA conversion of SQL codes further includes:
and the built-in function registration unit is used for acquiring built-in functions of the Oracle database so as to perform local registration.
In this embodiment, in order to increase the adaptability of the technical platform, the built-in function of Oracle is implemented and registered in the technical platform, so that the converted standard SQL can also support the built-in function of Oracle.
The method realizes the automatic conversion of the SQL statement into the executable Java code without manual adjustment, improves the conversion efficiency and reduces the conversion error rate.
The device synchronously updates the stored data to each node by adopting a two-stage submission algorithm, supports a distributed lock mechanism, and realizes the consistency of distributed storage of the data by using a pessimistic lock or an optimistic lock when the data is accessed.
The above-described JAVA conversion means of the SQL code may be implemented in the form of a computer program that can be run on a computer device as shown in fig. 5.
Referring to fig. 5, fig. 5 is a schematic block diagram of a computer device according to an embodiment of the present invention. The computer device 500 is a server, and the server may be an independent server or a server cluster composed of a plurality of servers.
Referring to fig. 5, the computer device 500 includes a processor 502, memory, and a network interface 505 connected by a system bus 501, where the memory may include a non-volatile storage medium 503 and an internal memory 504.
The non-volatile storage medium 503 may store an operating system 5031 and a computer program 5032. The computer program 5032, when executed, causes the processor 502 to perform a JAVA translation method of SQL code.
The processor 502 is used to provide computing and control capabilities that support the operation of the overall computer device 500.
The internal memory 504 provides an environment for the operation of the computer program 5032 in the non-volatile storage medium 503, and when the computer program 5032 is executed by the processor 502, the processor 502 can be enabled to execute the JAVA conversion method of the SQL code.
The network interface 505 is used for network communication, such as providing transmission of data information. Those skilled in the art will appreciate that the configuration shown in fig. 5 is a block diagram of only a portion of the configuration associated with aspects of the present invention and is not intended to limit the computing device 500 to which aspects of the present invention may be applied, and that a particular computing device 500 may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
The processor 502 is configured to run the computer program 5032 stored in the memory to implement the JAVA conversion method of the SQL code disclosed in the embodiment of the present invention.
Those skilled in the art will appreciate that the embodiment of a computer device illustrated in fig. 5 does not constitute a limitation on the specific construction of the computer device, and that in other embodiments a computer device may include more or fewer components than those illustrated, or some components may be combined, or a different arrangement of components. For example, in some embodiments, the computer device may only include a memory and a processor, and in such embodiments, the structures and functions of the memory and the processor are consistent with those of the embodiment shown in fig. 5, and are not described herein again.
It should be understood that, in the embodiment of the present invention, the Processor 502 may be a Central Processing Unit (CPU), and the Processor 502 may also be other general purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Wherein a general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
In another embodiment of the invention, a computer-readable storage medium is provided. The computer readable storage medium may be a non-volatile computer readable storage medium. The computer readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the JAVA conversion method of SQL codes disclosed in the embodiments of the present invention.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described apparatuses, devices and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again. Those of ordinary skill in the art will appreciate that the elements and algorithm steps of the examples described in connection with the embodiments disclosed herein may be embodied in electronic hardware, computer software, or combinations of both, and that the components and steps of the examples have been described in a functional general in the foregoing description for the purpose of illustrating clearly the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
In the embodiments provided by the present invention, it should be understood that the disclosed apparatus, device and method can be implemented in other ways. For example, the above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only a logical division, and there may be other divisions when the actual implementation is performed, or units having the same function may be grouped into one unit, for example, a plurality of units or components may be combined or may be integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may also be an electric, mechanical or other form of connection.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment of the present invention.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a storage medium. Based on such understanding, the technical solution of the present invention essentially or partially contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product stored in a storage medium and including instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a magnetic disk, or an optical disk.
While the invention has been described with reference to specific embodiments, the invention is not limited thereto, and various equivalent modifications and substitutions can be easily made by those skilled in the art within the technical scope of the invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (10)

1. A JAVA conversion method of SQL codes is characterized by comprising the following steps:
acquiring an SQL sentence to be converted, and carrying out lexical analysis on the SQL sentence to be converted according to the called first regular expression set to obtain a lexical analysis result;
carrying out syntactic analysis on the lexical analysis result to obtain a corresponding abstract syntactic tree;
performing semantic analysis on the abstract syntax tree to obtain context information;
performing Java grammar conversion on the lexical analysis result and the context information to obtain a fine-tuned syntax tree and fine-tuned context information; and
and calling a pre-stored code template, and filling the fine-tuned syntax tree and the fine-tuned context information into the code template to obtain a target Java code.
2. The JAVA conversion method of SQL codes according to claim 1, wherein the performing lexical analysis on the SQL statements to be converted according to the called first regular expression set to obtain a lexical analysis result comprises:
converting the called first regular expression set into a non-deterministic finite state automaton through the called Topson algorithm;
converting the non-deterministic finite state automaton into a deterministic finite state machine by a subset construction method;
simplifying the determined finite state machine into a minimum state determined finite state machine through a segmentation method to obtain a conversion table corresponding to the minimum state determined finite state machine;
calling a preset finite state machine simulator to form a lexical analyzer together with the conversion table;
and inputting the SQL sentence to be converted into the lexical analyzer to obtain a lexical analysis result through conversion.
3. The JAVA conversion method for SQL codes according to claim 1, wherein the parsing the lexical analysis result to obtain the corresponding abstract syntax tree comprises:
and carrying out syntactic analysis on the lexical analysis result through a Bison syntactic analyzer to obtain a corresponding abstract syntactic tree.
4. The JAVA translation method for SQL codes according to claim 3, wherein the parsing the lexical analysis result through the Bison parser to obtain the corresponding abstract syntax tree, comprising:
acquiring list information in a Bison grammar analyzer; the list information comprises a table list, an order list and an item list;
storing table information in the lexical analysis result in a table list, storing information in order clauses in the lexical analysis result in an order list, and storing information in where clauses in an item list;
and correspondingly acquiring the abstract syntax tree according to the list information of the currently stored data.
5. The JAVA translation method for SQL codes according to claim 1, wherein the semantic analyzing the abstract syntax tree to obtain context information comprises:
and sequentially carrying out variable reference resolution, type name resolution, type definition check, expression validity check and static type check on the abstract syntax tree to obtain context information.
6. The JAVA conversion method of SQL codes according to claim 1, further comprising:
the built-in functions of the Oracle database are obtained to register locally.
7. The JAVA conversion method for SQL codes according to claim 1, wherein the JAVA grammar conversion for the lexical analysis result and the context information to obtain the fine-tuned syntax tree and the fine-tuned context information comprises:
and obtaining the lexical analysis result and the type representation and the cycle statement in the context information, and converting the type representation and the cycle statement into Java type representation and Java cycle statement under a Java grammar so as to obtain a fine-tuned syntax tree and fine-tuned context information.
8. A JAVA conversion apparatus for SQL codes, comprising:
the lexical analysis unit is used for acquiring the SQL sentences to be converted, and carrying out lexical analysis on the SQL sentences to be converted according to the called first regular expression set to obtain lexical analysis results;
the syntactic analysis unit is used for carrying out syntactic analysis on the lexical analysis result to obtain a corresponding abstract syntactic tree;
the semantic analysis unit is used for performing semantic analysis on the abstract syntax tree to obtain context information;
the fine tuning unit is used for performing Java grammar conversion on the lexical analysis result and the context information to obtain a fine-tuned syntax tree and fine-tuned context information; and
and the code filling unit is used for calling a pre-stored code template, and filling the fine-tuned syntax tree and the fine-tuned context information into the code template to obtain the target Java code.
9. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the JAVA conversion method of SQL codes according to any of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that it stores a computer program which, when executed by a processor, causes the processor to execute the method for JAVA conversion of SQL codes according to any of claims 1 to 7.
CN202011244905.5A 2020-11-10 2020-11-10 JAVA conversion method and device of SQL (structured query language) code, computer equipment and storage medium Pending CN112363727A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011244905.5A CN112363727A (en) 2020-11-10 2020-11-10 JAVA conversion method and device of SQL (structured query language) code, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011244905.5A CN112363727A (en) 2020-11-10 2020-11-10 JAVA conversion method and device of SQL (structured query language) code, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
CN112363727A true CN112363727A (en) 2021-02-12

Family

ID=74508587

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011244905.5A Pending CN112363727A (en) 2020-11-10 2020-11-10 JAVA conversion method and device of SQL (structured query language) code, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN112363727A (en)

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113010183A (en) * 2021-04-30 2021-06-22 中国工商银行股份有限公司 Code conversion method and device
CN113127124A (en) * 2021-04-21 2021-07-16 平安付科技服务有限公司 Database language type switching method and device, computer equipment and storage medium
CN113312373A (en) * 2021-05-12 2021-08-27 上海哲锦信息科技有限公司 Method and equipment for analyzing data structured query statement
CN113467785A (en) * 2021-07-19 2021-10-01 上海红阵信息科技有限公司 SQL translation method and system for mimicry database
CN114816425A (en) * 2022-04-27 2022-07-29 珠海市奥德维科技有限公司 Method, system, electronic device and storage medium for converting an automation language program into a LUA language program
CN115509514A (en) * 2022-11-23 2022-12-23 济南浪潮数据技术有限公司 Front-end data simulation method, device, equipment and medium
CN117555925A (en) * 2024-01-12 2024-02-13 恒生电子股份有限公司 Database access code conversion method and device and electronic equipment
CN117555925B (en) * 2024-01-12 2024-05-10 恒生电子股份有限公司 Database access code conversion method and device and electronic equipment

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109992259A (en) * 2019-04-15 2019-07-09 成都四方伟业软件股份有限公司 Function dynamic creation method, apparatus and electronic equipment
CN110008448A (en) * 2019-04-02 2019-07-12 中国工商银行股份有限公司 The method and apparatus that SQL code is automatically converted to Java code
CN110018829A (en) * 2019-04-01 2019-07-16 北京东方国信科技股份有限公司 Improve the method and device of PL/SQL language interpreter execution efficiency
CN110825384A (en) * 2019-10-28 2020-02-21 国电南瑞科技股份有限公司 ST language compiling method, system and compiler based on LLVM
CN110851142A (en) * 2019-10-18 2020-02-28 浙江大学 Method for converting Transact-SQL program into Java program
CN111580825A (en) * 2020-04-28 2020-08-25 中国科学院软件研究所 Compiling method and system for mechanical arm program development programming language

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110018829A (en) * 2019-04-01 2019-07-16 北京东方国信科技股份有限公司 Improve the method and device of PL/SQL language interpreter execution efficiency
CN110008448A (en) * 2019-04-02 2019-07-12 中国工商银行股份有限公司 The method and apparatus that SQL code is automatically converted to Java code
CN109992259A (en) * 2019-04-15 2019-07-09 成都四方伟业软件股份有限公司 Function dynamic creation method, apparatus and electronic equipment
CN110851142A (en) * 2019-10-18 2020-02-28 浙江大学 Method for converting Transact-SQL program into Java program
CN110825384A (en) * 2019-10-28 2020-02-21 国电南瑞科技股份有限公司 ST language compiling method, system and compiler based on LLVM
CN111580825A (en) * 2020-04-28 2020-08-25 中国科学院软件研究所 Compiling method and system for mechanical arm program development programming language

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
广友: "SQL解析在美团的应用", 《HTTPS://TECH.MEITUAN.COM/2018/05/20/SQL-PARSER-USED-IN-MTDP.HTML》 *
张弦等: "GPJ_Pascal集成开发坏境――词法分析、语法分析、语义分析和中间代码生成", 《广西工学院学报》 *

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113127124A (en) * 2021-04-21 2021-07-16 平安付科技服务有限公司 Database language type switching method and device, computer equipment and storage medium
CN113010183A (en) * 2021-04-30 2021-06-22 中国工商银行股份有限公司 Code conversion method and device
CN113312373A (en) * 2021-05-12 2021-08-27 上海哲锦信息科技有限公司 Method and equipment for analyzing data structured query statement
CN113467785A (en) * 2021-07-19 2021-10-01 上海红阵信息科技有限公司 SQL translation method and system for mimicry database
CN113467785B (en) * 2021-07-19 2023-02-28 上海红阵信息科技有限公司 SQL translation method and system for mimicry database
CN114816425A (en) * 2022-04-27 2022-07-29 珠海市奥德维科技有限公司 Method, system, electronic device and storage medium for converting an automation language program into a LUA language program
CN115509514A (en) * 2022-11-23 2022-12-23 济南浪潮数据技术有限公司 Front-end data simulation method, device, equipment and medium
CN115509514B (en) * 2022-11-23 2023-03-10 济南浪潮数据技术有限公司 Front-end data simulation method, device, equipment and medium
CN117555925A (en) * 2024-01-12 2024-02-13 恒生电子股份有限公司 Database access code conversion method and device and electronic equipment
CN117555925B (en) * 2024-01-12 2024-05-10 恒生电子股份有限公司 Database access code conversion method and device and electronic equipment

Similar Documents

Publication Publication Date Title
CN112363727A (en) JAVA conversion method and device of SQL (structured query language) code, computer equipment and storage medium
Thomas et al. Making BUGS open
JP5431513B2 (en) Interpreting command scripts using local and extended storage for command indexing
US9058360B2 (en) Extensible language framework using data cartridges
Brabrand et al. Powerforms: Declarative client-side form field validation
US20070255751A1 (en) Method to transform meta object facility specifications into relational data definition language structures and JAVA classes
WO1996013784A2 (en) Method and apparatus for tree data structure manipulation and translating source code from one high-level computer language to another
WO1996013784A9 (en) Method and apparatus for tree data structure manipulation and translating source code from one high-level computer language to another
CN108694214A (en) Generation method, generating means, readable medium and the electronic equipment of data sheet
CN113504900A (en) Programming language conversion method and device
US11275625B2 (en) System and method for automated application programming interface generation
WO2014125430A1 (en) Method for creating specifications of software systems, in particular of the oltp-app type, and device thereof
Nguyen et al. Output-oriented refactoring in php-based dynamic web applications
Syme et al. The F# 2.0 language specification
US11550556B1 (en) Efficient semantic analysis of program code
EP0990983A1 (en) Automation of the design recovery and forward engineering of legacy applications
CN110058858B (en) JSON data processing method and device
CN112363832B (en) Ignite-based distributed data processing method and device and computer equipment
CN116627390B (en) ICD file substitution method and device in aviation software development
Myalapalli et al. Overhauling PL/SQL applications for optimized performance
US20230080220A1 (en) System and method for executing compiled user defined functions in vectorized databases
KR100656559B1 (en) Program Automatic Generating Tools
Libes The NIST EXPRESS Toolkit: Using Applications
CN114942766A (en) Excel function conversion method based on SQL database and related device
Ahmed Paradigm of Programming Ruby language Ghanim Hussein Ali Ahmed

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20210212

RJ01 Rejection of invention patent application after publication