CN113220709B - Grammar processing method, device, equipment and storage medium for operation database - Google Patents

Grammar processing method, device, equipment and storage medium for operation database Download PDF

Info

Publication number
CN113220709B
CN113220709B CN202110506562.3A CN202110506562A CN113220709B CN 113220709 B CN113220709 B CN 113220709B CN 202110506562 A CN202110506562 A CN 202110506562A CN 113220709 B CN113220709 B CN 113220709B
Authority
CN
China
Prior art keywords
grammar
database
target
tree
type
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.)
Active
Application number
CN202110506562.3A
Other languages
Chinese (zh)
Other versions
CN113220709A (en
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.)
CCB Finetech Co Ltd
Original Assignee
CCB Finetech Co 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 CCB Finetech Co Ltd filed Critical CCB Finetech Co Ltd
Priority to CN202110506562.3A priority Critical patent/CN113220709B/en
Publication of CN113220709A publication Critical patent/CN113220709A/en
Application granted granted Critical
Publication of CN113220709B publication Critical patent/CN113220709B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • 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
    • 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
    • G06F16/2445Data retrieval commands; View definitions
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/237Lexical tools
    • G06F40/247Thesauruses; Synonyms
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/253Grammatical analysis; Style critique
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/279Recognition of textual entities
    • G06F40/284Lexical analysis, e.g. tokenisation or collocates
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Computational Linguistics (AREA)
  • General Physics & Mathematics (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • General Health & Medical Sciences (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Mathematical Physics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a grammar processing method, device and equipment for an operation database and a storage medium, and relates to the technical field of Internet. The method comprises the following steps: carrying out grammar processing on the functional expression to be processed by utilizing a pre-generated grammar analyzer, and generating a corresponding grammar tree with a database type label; and carrying out synonymous replacement on the nodes of the non-target type grammar in the grammar tree to obtain the target functional expression conforming to the target type grammar. According to the embodiment of the invention, the grammar analyzer generates the grammar tree with the affiliated database type label, and the nodes of the non-target type grammar in the grammar tree are synonymously replaced to obtain the target functional expression conforming to the target type grammar, so that the purposes of accurately identifying the non-target type grammar and giving the modification opinion are realized.

Description

Grammar processing method, device, equipment and storage medium for operation database
Technical Field
The embodiment of the invention relates to the technical field of Internet, in particular to a grammar processing method, device, equipment and storage medium for an operation database.
Background
Because of the characteristics of open ecology, easy expansion, easy migration and free of MySQL database, the Internet industry takes the mainstream position, and the traditional industry is permeated, and the SQL grammar of MySQL also becomes the mainstream grammar implementation standard of the national self-research database. A large number of traditional business database users are also considering and practicing migrating data onto MySQL or MySQL ecosystems' self-research databases. However, because the SQL grammar definition, function name, data type definition and the like of each database are different, the database migration is not only to migrate data, but also to modify the SQL compatibility of the operation database by a service realization party, and a great deal of labor is required to be input, which is a great pain point for database migration.
Disclosure of Invention
In view of the above, the present invention provides a grammar processing method, apparatus, device and storage medium for operating a database, which can accurately identify non-target type grammars in a functional expression to be processed and perform synonymous substitution to obtain a target functional expression conforming to the target type grammar.
In a first aspect, an embodiment of the present invention provides a method for processing grammar of an operation database, including:
carrying out grammar processing on the functional expression to be processed by utilizing a pre-generated grammar analyzer, and generating a corresponding grammar tree with a database type label;
and carrying out synonymous replacement on the nodes of the non-target type grammar in the grammar tree to obtain the target functional expression conforming to the target type grammar.
In a second aspect, an embodiment of the present invention further provides a syntax processing apparatus for operating a database, including:
the grammar processing module is used for carrying out grammar processing on the functional expression to be processed by utilizing a pre-generated grammar analyzer and generating a corresponding grammar tree with a database type label;
and the replacing module is used for synonymously replacing the nodes of the non-target type grammar in the grammar tree to obtain the target functional expression conforming to the target type grammar.
In a third aspect, an embodiment of the present invention further provides a syntax processing apparatus for operating a database, the apparatus including:
one or more processors;
a memory for storing one or more programs,
the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the method of syntax processing for operating a database as described in any of the embodiments above.
In a fourth aspect, embodiments of the present invention further provide a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements a method for processing a grammar for operating a database according to any one of the embodiments of the present invention.
The embodiment of the invention carries out grammar processing on the functional expression to be processed by utilizing a pre-generated grammar analyzer to generate a corresponding grammar tree with a database type label; and carrying out synonymous replacement on the nodes of the non-target type grammar in the grammar tree to obtain the target functional expression conforming to the target type grammar. According to the embodiment of the invention, the grammar analyzer generates the grammar tree with the affiliated database type label, and the nodes of the non-target type grammar in the grammar tree are synonymously replaced to obtain the target functional expression conforming to the target type grammar, so that the purposes of accurately identifying the non-target type grammar and giving the modification opinion are realized.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings that are needed in the embodiments will be briefly described below, it being understood that the following drawings only illustrate some embodiments of the present invention and therefore should not be considered as limiting the scope, and other related drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flowchart of a method for processing grammar for operating a database according to an embodiment of the present invention;
FIG. 2 is a schematic diagram illustrating generation of a syntax tree according to an embodiment of the present invention;
FIG. 3 is a flowchart of another method for processing grammar for operating a database according to an embodiment of the present invention;
FIG. 4 is a flow chart of yet another method of grammar processing for operating a database provided by an embodiment of the present invention;
FIG. 5 is a schematic diagram of a syntax tree according to an embodiment of the present invention;
FIG. 6 is a schematic diagram of a target functional expression according to an embodiment of the present invention;
fig. 7 is a schematic structural diagram of a syntax processing device for operating a database according to an embodiment of the present invention;
fig. 8 is a schematic structural diagram of a syntax processing device for operating a database according to an embodiment of the present invention.
Detailed Description
The invention is described in further detail below with reference to the drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting thereof. It should be further noted that, for convenience of description, only some, but not all of the structures related to the present invention are shown in the drawings.
It should be noted that: like reference numerals and letters denote like items in the following figures, and thus once an item is defined in one figure, no further definition or explanation thereof is necessary in the following figures. Meanwhile, in the description of the present invention, the terms "first", "second", and the like are used only to distinguish the description, and are not to be construed as indicating or implying relative importance.
In the direction of business SQL, conversion tools and open source tools provided by commercial database manufacturers currently have various problems for SQL support. Taking Oracle Goldengate as an example, the method is a data conversion and replication tool, does not provide a DDL conversion function and further does not provide support of service SQL; in addition to this, open-sourced Sqlines is the most widely used SQL transformation tool. It requires specifying the source database type, has problems in terms of SQL syntax support,
for example, input DB2 syntax: select from A fetch first rows only; output, not conforming to MySQL syntax: select from A fetch first Rows only
As another example, an Oracle syntax is entered: select a.a1|a.a2 from a where a.a1>0for update wait 10; output, || is correctly transformed into a concat function, but wait n does not conform to MySQL syntax: select concat (Ifnull (a.a1, "), ifnull (a.a2,")) from a window a.a1>0for update wait 10
Since the recognition capability of SQL grammar by Sqlines is still problematic, the effect of saving labor investment in production practice is very limited. And simultaneously, the grammar analysis of various databases is respectively and independently realized, and the difficulty of secondarily developing and expanding functions based on the grammar analysis is high.
Therefore, the embodiment of the invention constructs a tool which is easy to expand and well supports a plurality of database SQL standards, can accurately identify SQL grammar of non-MySQL standards and gives modification comments.
In an embodiment, fig. 1 is a flowchart of a method for processing grammar of an operation database according to an embodiment of the present invention, where the embodiment may be applicable to a case where nodes of a non-target type grammar are accurately identified and synonymously replaced, the method may be performed by a grammar processing apparatus of the operation database according to an embodiment of the present invention, and the apparatus may be implemented in a software and/or hardware manner. Wherein the syntax processing means of the operation database are integrated in the syntax processing device of the operation database. The grammar processing device of the operation database can be a computer device, a notebook computer, an ipad and other terminal devices.
As shown in fig. 1, the method specifically includes the following steps:
s110, carrying out grammar processing on the functional expression to be processed by utilizing a pre-generated grammar analyzer, and generating a corresponding grammar tree with the type tag of the database.
The function of the parser is to perform a grammar check and construct a data structure composed of the input words (wherein the data structure is generally a hierarchical data structure such as a parse tree, an abstract syntax tree, etc.). The parser typically uses a separate lexical analyzer to separate individual "words" from the input character stream and takes the word stream as its input. In the actual development process, the parser may be written manually, or may be automatically or semi-automatically generated using tools. Fig. 2 is a schematic diagram illustrating generation of a syntax tree according to an embodiment of the present invention. As shown in fig. 2, the yacc Parser is used as the tool corresponding to the grammar rule in the present embodiment, the lex lexical Parser is used as the tool corresponding to the lexical rule, and the functional expression to be processed and the yacc Parser are input to the Parser, so that the yacc Parser processes the functional expression to be processed in a grammar manner, and a corresponding grammar tree with the database type to which the yacc parse belongs is generated.
It should be noted here that the syntax tree is a graphic representation of a sentence structure, which represents the derivation of the sentence, and is useful for understanding the hierarchy of the sentence syntax structure. In short, a syntax tree is a tree formed when a derivation is performed according to a certain rule. The to-be-processed functional expression refers to a statement containing SQL grammar, namely the to-be-processed functional expression is a source SQL statement. Of course, clauses other than MySQL grammar may also be included in the pending functional expression.
In an embodiment, a syntax analyzer is utilized to process the functional expression to be processed, and a generated syntax tree with a database type label is generated, wherein the database type label refers to all database types contained in the functional expression to be processed. It is understood that the functional expression to be processed is an SQL statement, but the functional expression to be processed contains an SQL grammar and can also contain other database types. Illustratively, in the case of the pending functional expression containing an SQL grammar, a DB2 grammar, the associated database type tags in the grammar tree include: SQL database, DB2 database. It will be appreciated that the database type tags carried in the syntax tree are related to the syntax types contained in the functional expression to be processed, i.e. the database type tags are in one-to-one correspondence with the syntax types.
S120, carrying out synonymous replacement on nodes of the non-target type grammar in the grammar tree to obtain a target functional expression conforming to the target type grammar.
In an embodiment, the target type grammar refers to a structured query language (Structured Query Language, SQL) grammar. The SQL is a special purpose programming language, and is a database query and programming language for accessing data and querying, updating and managing a relational database system. Accordingly, non-object type grammars refer to non-SQL grammars, e.g., non-object type grammars may include: DB2 syntax, oracle syntax, and the like, are not limited thereto.
In the embodiment, after the to-be-processed functional expression is obtained, a corresponding database type label can be searched from a grammar tree corresponding to the to-be-processed functional expression, so that nodes of non-target type grammar in the grammar tree can be accurately obtained; and then replacing clause synonyms corresponding to the non-target type grammar with clauses of the corresponding target type grammar to obtain the target functional expression conforming to the target type grammar. It is understood that the functional expression to be processed may include an SQL grammar, or may include other grammars, such as a DB2 grammar and an Oracle grammar; but only the SQL syntax is included in the target functional expression.
According to the technical scheme, a pre-generated grammar analyzer is utilized to carry out grammar processing on the functional expression to be processed, and a corresponding grammar tree with a database type label is generated; and carrying out synonymous replacement on the nodes of the non-target type grammar in the grammar tree to obtain the target functional expression conforming to the target type grammar. According to the embodiment of the invention, the grammar analyzer generates the grammar tree with the affiliated database type label, and the nodes of the non-target type grammar in the grammar tree are synonymously replaced to obtain the target functional expression conforming to the target type grammar, so that the purposes of accurately identifying the non-target type grammar and giving the modification opinion are realized.
In one embodiment, fig. 3 is a flowchart of another method for processing grammar in an operation database according to an embodiment of the present invention. The present embodiment further describes a syntax processing method for operating the database based on the above embodiments. As shown in fig. 3, the syntax processing method of the operation database in the present embodiment includes the steps of:
s310, creating a grammar rule set supporting a preset database.
The preset database refers to various databases contained in the prior art, and exemplary preset databases may be DB2 databases, oracle databases, or SQL databases, which are not limited thereto. Wherein the grammar rule set is used for containing a defined set of grammar rules, i.e. a plurality of grammar rules are contained in the grammar rule set. In an embodiment, S210 includes: S2101-S2102.
S3101, marking the corresponding database label on the target grammar element.
Wherein, the target syntax element refers to the syntax element of the database label to be marked. In embodiment china, in the process of defining the grammar rules, it is required to tag the grammar element with the tag of which database the grammar element belongs to, that is, the grammar element tagged with the tag of the database is required to be the target grammar element. Accordingly, the database tag refers to the database type of the target syntax element.
S3102, the target grammar elements and the corresponding database labels form a corresponding grammar rule set.
In an embodiment, after determining the database tag corresponding to each target syntax element, the target syntax element and the corresponding database tag are combined to obtain the corresponding syntax rule set. Illustratively, the generation process of the grammar rule set will be described assuming that "return only the first $1 line, at most $2 wait" as an example. The grammar rule set includes the following: the first line is a grammar function and includes three possible grammars, each of which may belong to one or more databases. The pseudo code is expressed as follows:
the limit phrase includes the following cases:
limit count { belonging database: [ Oracle, mySQL ] }
Alternatively, limit offset, count { belonging to database: [ Oracle, mySQL ] }
Alternatively, the fetch first count rows only { belonging to the database: [ DB2] }
Because the same word or symbol may represent different meanings in different databases, a parser is required to perform special processing on some grammar rules. For example, the "|" symbol represents a string connection in some databases and a logical OR in other databases. In the parser of this embodiment, since the target databases are MySQL, logic OR another more general expression "OR", the "|" operators are all processed by string concatenation.
S320, generating a corresponding grammar analyzer by using the grammar rule set.
After defining a grammar rule set for supporting multiple databases simultaneously, a corresponding grammar analyzer is generated, and the grammar analyzer has the supporting and marking capability for multiple database grammars. However, if the input SQL does not conform to the defined grammar in any grammar rule set, the SQL cannot be compiled by a grammar analyzer and is directly reported by mistake. S330, utilizing a pre-generated grammar analyzer to carry out grammar analysis on the functional expression to be processed, and obtaining a corresponding grammar element.
In an embodiment, the functional expression to be processed is parsed by using syntax analysis, that is, the functional expression to be processed is split, so as to obtain all the syntax elements contained. Wherein, the syntax elements refer to clauses, fields, expressions, etc. contained in the functional expression to be processed.
S340, determining the type of the affiliated database and the position of the node corresponding to each syntax element.
In an embodiment, each syntax element corresponds to one of the belonging database types and node positions. It is understood that each syntax element is a leaf node, or a non-leaf node, in the syntax tree.
S350, laying out each syntax element according to the node position, and generating a corresponding syntax tree with the affiliated database type label.
In an embodiment, each syntax element is laid out according to the node position according to the functional expression to be processed, so as to determine the position of each syntax element in the syntax tree, and thus the corresponding syntax tree can be obtained. Of course, in order to facilitate more intuitive deriving of the belonging database type for each syntax element from the syntax tree, the corresponding belonging database type is configured for each syntax element in the syntax tree. Of course, the database type to which the syntax element corresponding to the non-target type syntax belongs can be marked, so that the database type label to which all the syntax elements in the functional expression to be processed belong is avoided, and further the simplicity of the syntax tree is ensured.
In one embodiment, the nodes in the syntax tree include the following attributes: the grammar function type of the node; a sub-node reference relationship; an original character string represented by the node; database type labels of nodes. In an embodiment, for leaf nodes in the syntax tree, the original string is constant; for non-leaf nodes in the syntax tree, the original string is an expression or clause.
S360, traversing the grammar tree to obtain the corresponding node of the non-target type grammar.
In the grammar tree, the grammar elements corresponding to the non-target type grammar are marked with the type of the affiliated database, so that the grammar elements corresponding to the non-target type grammar, namely the nodes of the non-target type grammar, can be directly obtained in the process of traversing the grammar tree.
And S370, traversing subtrees in the grammar tree to obtain corresponding original input character strings.
In an embodiment, each node in the syntax tree has a recovery function; the recovery function is used for reserving the corresponding original character strings and the grammar function of each node on each node in the grammar parsing process.
S380, synonymous replacement is carried out on clauses corresponding to nodes of non-target type grammar according to target type grammar corresponding to the target database, and target functional expression conforming to the target type grammar is obtained.
In an embodiment, the process of obtaining the target functional expression, i.e., the process of recovering the syntax tree. In the embodiment, in order to accurately restore the grammar tree to the corresponding target function expression, the subtrees in the grammar tree are traversed to obtain the original character strings reserved on the nodes corresponding to each subtree and the grammar function of each node.
S380 includes: S3801-S3802:
s3801, performing synonymous replacement on clauses corresponding to nodes of non-target type grammar according to target type grammar corresponding to the target database to obtain target clauses conforming to the target type grammar.
In the traversal process, on the basis that nodes in the grammar tree are marked with database type labels, the expressions of the grammar function are organized according to different database types, and clauses needing database type conversion can be synonymously replaced when subtrees are recovered, namely, clauses corresponding to nodes of non-target type grammar are synonymously replaced, so that target clauses conforming to target type grammar are obtained.
S3802, combining the original input character string and the target clause into a corresponding target functional expression.
In an embodiment, the original input string and the target clause are combined to obtain a target functional expression synonymous with input and conforming to MySQL grammar.
In one embodiment, fig. 4 is a flowchart of another method for processing grammar for operating a database according to an embodiment of the present invention. In the embodiment, the syntax processing process of the operation database is described by taking the to-be-processed functional expression as a source SQL and the target type syntax as an SQL syntax as an example. The embodiment is to construct a tool which is easy to expand and well supports a plurality of database SQL standards, can accurately identify SQL grammar of non-MySQL standards and gives modification comments. As shown in fig. 4, the syntax processing method of the operation database in the present embodiment includes the steps of:
s410, carrying out compatibility and distinction on different database grammars.
In an embodiment, in order to ensure that the tool can identify the grammars of different databases, firstly, the grammar of a source end and a destination end is required to be supported simultaneously, and mark and distinguish. Table 1 is a syntax analysis table of the same syntax function and different databases provided in the embodiment of the present invention. As shown in table 1, the same grammar function, different database grammars, are listed with an example illustration using a limit and "|" connector.
Figure BDA0003058665160000111
In the definition of grammar rules, a tag of which database the grammar element belongs to needs to be marked on the grammar element. In the embodiments, the examples of the syntax element marking database type label are described in the above embodiments, and are not described herein.
S420, generating a grammar analyzer by using a grammar rule set supporting a plurality of database grammars.
S430, generating a grammar tree with the affiliated database type label by using a grammar analyzer.
In an embodiment, a corresponding syntax tree is generated using a syntax analyzer with an associated database type tag. The node attribute of each node in the grammar tree comprises: the grammar function type of the node; a sub-node reference relationship; an original character string represented by the node; database type labels of nodes. Wherein, the reference relation of the child node refers to that the node is not the smallest syntax element, i.e. is not a leaf node. For leaf nodes in the grammar tree, the original character string is constant; for non-leaf nodes in the syntax tree, the original string is an expression or clause. In the actual operation process, not every node in the grammar tree is provided with a corresponding database type label, and it is to be noted that the SQL grammar of most databases has universality and the difference part is considered when the grammars are compatible.
Fig. 5 is a schematic structural diagram of a syntax tree according to an embodiment of the present invention. As shown in fig. 5, in the output syntax tree, the nodes of the "|" and "fetch" clauses are labeled with the labels of the corresponding databases. In this way, the user can be accurately located and informed of the input of portions of SQL (pending functional expressions) that do not conform to MySQL syntax.
S440, performing synonymous replacement on the non-MySQL grammar in the source SQL by using a multi-library grammar rule.
In the embodiment, each node has a reverse method for restoring a sub-tree in the syntax tree into an original input SQL character string by using the original character string reserved on each node in the syntax analysis process and the syntax function of each node.
By traversing the entire syntax tree, the full original input SQL can be restored. Fig. 6 is a schematic structural diagram of a target functional expression according to an embodiment of the present invention. As shown in fig. 6, in the traversal process, on the basis of the labeled database type labels of the nodes in the grammar tree, the expressions of the grammar function are organized according to different database types, and when the subtree is recovered, clauses needing database type conversion can be synonymously replaced, so that the complete SQL which is synonymous with input and accords with MySQL grammar can be obtained.
Illustratively, a DB2 syntax is entered:
select t.A t1.B from t left join t1 on t.id=t1. Tid wheree (not shown) fetch first 30rows only
Outputting MySQL grammar:
select concat (t.A, t1. B) from t left join t on t.id=t1.tid wherem (abbreviation) limit 0,30
According to the technical scheme, multiple definitions are carried out on the same functional expression, and the database type labels are added, so that automatic generation of a grammar analyzer is realized only by modifying grammar rules, and recognition is carried out while multiple types of database grammar are compatible; the service SQL adaptation in grammar correction user database migration is realized through subtree replacement with different types and the same grammar function, the tool can automatically identify various types of database grammar, can perform function expansion by self-defining grammar, and can accurately position character string boundaries of different types of grammar and accurately replace the character string boundaries.
Of course, in the actual operation process, the nodes of the non-target type grammar in the SQL sentence can be replaced by synonyms manually by a development engineer, so that the target functional expression conforming to the target type grammar can be obtained.
Fig. 7 is a schematic structural diagram of a syntax processing device for operating a database according to an embodiment of the present invention. The embodiment is applied to a case of precisely identifying a node of a non-target type grammar and performing synonymous replacement, and as shown in fig. 7, the grammar processing device of the operation database specifically includes: a grammar processing module 710 and a replacement module 720.
The grammar processing module 710 is configured to process the to-be-processed functional expression by using a pre-generated grammar analyzer, and generate a corresponding grammar tree with a database type tag;
and a replacing module 720, configured to perform synonymous replacement on nodes in the grammar tree that are not the target type grammar, so as to obtain a target functional expression that accords with the target type grammar.
According to the technical scheme of the embodiment, the grammar processing device for the operation database further comprises:
the creating module is used for creating a grammar rule set supporting a preset database before carrying out grammar processing on the functional expression to be processed by utilizing a pre-generated grammar analyzer;
and the generation module is used for generating a corresponding grammar analyzer by utilizing the grammar rule set.
On the basis of the above embodiment, the syntax processing module for operating a database includes:
a grammar decomposition unit, configured to perform grammar decomposition on the functional expression to be processed by using a pre-generated grammar analyzer, so as to obtain a corresponding grammar element;
the determining unit is used for determining the type of the affiliated database and the node position corresponding to each syntax element;
and the generating unit is used for carrying out layout on each syntax element according to the node position and generating a corresponding syntax tree with the affiliated database type label.
On the basis of the embodiment, each node in the grammar tree has a recovery function; the recovery function is used for reserving the corresponding original character string and the grammar function of each node on each node in the grammar parsing process.
On the basis of the above embodiment, the replacement module includes:
the first traversing unit is used for traversing the grammar tree to obtain the corresponding node of the non-target type grammar;
and the replacing unit is used for synonymously replacing clauses corresponding to nodes of the non-target type grammar according to the target type grammar corresponding to the target database to obtain a target functional expression conforming to the target type grammar.
On the basis of the above embodiment, the replacement module further includes:
the second traversing unit is used for traversing subtrees in the grammar tree before synonymous replacement is carried out on clauses corresponding to nodes of non-target type grammar according to target type grammar corresponding to the target database, so as to obtain corresponding original input character strings.
On the basis of the above embodiment, the replacement unit includes:
a replacing subunit, configured to synonymously replace clauses corresponding to nodes of the non-target type grammar according to the target type grammar corresponding to the target database, so as to obtain target clauses that conform to the target type grammar;
and the combining subunit is used for combining the original input character string and the target clause into a corresponding target functional expression.
On the basis of the embodiment, in the case that the parser cannot process the functional expression to be processed in a grammar, a corresponding error report instruction is generated.
On the basis of the above embodiment, a creation module includes:
the marking unit is used for marking the corresponding database label on the target grammar element;
and the composing unit is used for composing the target grammar element and the corresponding database label into a corresponding grammar rule set.
On the basis of the above embodiment, the nodes in the syntax tree include the following attributes: the grammar function type of the node; a sub-node reference relationship; an original character string represented by the node; database type labels of nodes.
On the basis of the embodiment, aiming at leaf nodes in the grammar tree, the original character string is constant;
for non-leaf nodes in the syntax tree, the original string is an expression or clause.
Based on the above embodiment, the target database is MySQL; the preset database comprises one of the following types: oracle; DB2; mySQL.
The grammar processing device of the operation database provided by the embodiment can execute the grammar processing method of the operation database provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of executing the grammar processing method of the operation database.
Fig. 8 is a schematic structural diagram of a syntax processing device for operating a database according to an embodiment of the present invention. As shown in fig. 8, the syntax processing apparatus of the operation database includes a processor 810, a memory 820, an input device 830, and an output device 840; the number of processors 810 in the syntax processing device operating the database may be one or more, one processor 810 being taken as an example in fig. 8; the processor 810, memory 820, input means and 830 output means 840 in the syntax handling device operating the database may be connected by a bus or other means, in fig. 8 by way of example.
The memory 820 is a computer-readable storage medium that can be used to store a software program, a computer-executable program, and a module, such as a program module corresponding to a syntax processing method of an operation database in an embodiment of the present invention (e.g., a syntax processing module and a replacement module in a syntax processing apparatus of the operation database). The processor 810 performs various functional applications of the syntax processing apparatus for operating the database and data processing, that is, implements the syntax processing method for operating the database as described above, by running software programs, instructions, and modules stored in the memory 820.
Memory 820 may include primarily a program storage area and a data storage area, wherein the program storage area may store an operating system, at least one application program required for functionality; the storage data area may store data created according to the use of the terminal, etc. In addition, memory 820 may include high-speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid-state storage device. In some examples, memory 820 may further include memory remotely located with respect to data forwarding system 810, which may be connected to the vehicle via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and framing options thereof.
The input device 830 may be used to receive input numeric or character information and to generate key signal inputs related to user settings and function control of the vehicle. The output device 840 may include a display device such as a display screen.
The embodiments of the present invention also provide a storage medium containing computer-executable instructions, which when executed by a computer processor, are for performing a method of syntax processing for operating a database, the method comprising:
carrying out grammar processing on the functional expression to be processed by utilizing a pre-generated grammar analyzer, and generating a corresponding grammar tree with a database type label; and carrying out synonymous replacement on the nodes of the non-target type grammar in the grammar tree to obtain the target functional expression conforming to the target type grammar.
Of course, the storage medium containing the computer executable instructions provided in the embodiments of the present invention is not limited to the above method operations, and may also perform the related operations in the syntax processing method for operating the database provided in any embodiment of the present invention.
From the above description of embodiments, it will be clear to a person skilled in the art that the present invention may be implemented by means of software and necessary general purpose hardware, but of course also by means of hardware, although in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the prior art in the form of a software product, which may be stored in a computer readable storage medium, such as a floppy disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a FLASH Memory (FLASH), a hard disk or an optical disk of a computer, etc., and include several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method according to the embodiments of the present invention.
It should be noted that, in the embodiment of the text classification device, each unit and module included are only divided according to the functional logic, but not limited to the above division, so long as the corresponding functions can be implemented; in addition, the specific names of the functional units are also only for distinguishing from each other, and are not used to limit the protection scope of the present invention.
Note that the above is only a preferred embodiment of the present invention and the technical principle applied. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, while the invention has been described in connection with the above embodiments, the invention is not limited to the embodiments, but may be embodied in many other equivalent forms without departing from the spirit or scope of the invention, which is set forth in the following claims.

Claims (11)

1. A method of grammar processing for operating a database, comprising:
carrying out grammar processing on the functional expression to be processed by utilizing a pre-generated grammar analyzer, and generating a corresponding grammar tree with a database type label;
performing synonymous replacement on nodes of non-target type grammar in the grammar tree to obtain a target functional expression conforming to the target type grammar;
the method for generating the grammar tree with the database type label comprises the following steps of: utilizing a pre-generated grammar analyzer to carry out grammar analysis on the functional expression to be processed to obtain a corresponding grammar element; determining the type of the affiliated database and the position of the node corresponding to each syntax element; laying out each grammar element according to the node position to generate a corresponding grammar tree with a database type label;
the synonymous replacement is performed on the nodes of the non-target type grammar in the grammar tree to obtain a target functional expression conforming to the target type grammar, and the method comprises the following steps: traversing the grammar tree to obtain a node of a corresponding non-target type grammar; traversing subtrees in the grammar tree to obtain corresponding original input character strings; performing synonymous replacement on clauses corresponding to nodes of the non-target type grammar according to the target type grammar corresponding to the target database to obtain target clauses conforming to the target type grammar; and combining the original input character string and the target clause into a corresponding target functional expression.
2. The method of claim 1, further comprising, prior to said syntactically processing the functional expression to be processed using the pre-generated parser:
creating a grammar rule set supporting a preset database;
and generating a corresponding grammar analyzer by using the grammar rule set.
3. The method of claim 1, wherein each node in the syntax tree is provided with a restoration function; the recovery function is used for reserving the corresponding original character strings and the grammar function of each node on each node in the grammar parsing process.
4. The method of claim 1, wherein in the event that the parser is unable to parse a functional expression to be processed, a corresponding error indication is generated.
5. The method of claim 2, wherein creating a grammar rule set that supports a preset database comprises:
marking a corresponding database tag on the target syntax element;
and forming the target grammar element and the corresponding database label into a corresponding grammar rule set.
6. The method of any of claims 1-5, wherein nodes in the syntax tree comprise the following attributes: the grammar function type of the node; a sub-node reference relationship; an original character string represented by the node; database type labels of nodes.
7. The method of claim 6, wherein the original string is constant for leaf nodes in the syntax tree;
for non-leaf nodes in the syntax tree, the original string is an expression or clause.
8. The method of claim 1, wherein the target database is MySQL; the preset database comprises one of the following types: oracle; DB2; mySQL.
9. A syntax processing apparatus for operating a database, comprising:
the grammar processing module is used for carrying out grammar processing on the functional expression to be processed by utilizing a pre-generated grammar analyzer and generating a corresponding grammar tree with a database type label;
the replacing module is used for synonymously replacing the nodes of the non-target type grammar in the grammar tree to obtain a target functional expression conforming to the target type grammar;
wherein, the grammar processing module comprises: a grammar decomposition unit, configured to perform grammar decomposition on the functional expression to be processed by using a pre-generated grammar analyzer, so as to obtain a corresponding grammar element; the determining unit is used for determining the type of the affiliated database and the node position corresponding to each syntax element; the generating unit is used for carrying out layout on each syntax element according to the node position and generating a corresponding syntax tree with a database type label;
the replacement module comprises: the first traversing unit is used for traversing the grammar tree to obtain the corresponding node of the non-target type grammar; the second traversing unit is used for traversing subtrees in the grammar tree to obtain corresponding original input character strings; a replacing subunit, configured to synonymously replace clauses corresponding to nodes of the non-target type grammar according to the target type grammar corresponding to the target database, so as to obtain target clauses that conform to the target type grammar; and the combining subunit is used for combining the original input character string and the target clause into a corresponding target functional expression.
10. A syntax processing apparatus for operating a database, the apparatus comprising:
one or more processors;
a memory for storing one or more programs,
when executed by the one or more processors, causes the one or more processors to implement the method of syntax processing of an operations database as in any one of claims 1-8.
11. A computer-readable storage medium, on which a computer program is stored, characterized in that the program, when being executed by a processor, implements a syntax processing method of an operation database according to any one of claims 1-8.
CN202110506562.3A 2021-05-10 2021-05-10 Grammar processing method, device, equipment and storage medium for operation database Active CN113220709B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110506562.3A CN113220709B (en) 2021-05-10 2021-05-10 Grammar processing method, device, equipment and storage medium for operation database

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110506562.3A CN113220709B (en) 2021-05-10 2021-05-10 Grammar processing method, device, equipment and storage medium for operation database

Publications (2)

Publication Number Publication Date
CN113220709A CN113220709A (en) 2021-08-06
CN113220709B true CN113220709B (en) 2023-06-20

Family

ID=77094250

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110506562.3A Active CN113220709B (en) 2021-05-10 2021-05-10 Grammar processing method, device, equipment and storage medium for operation database

Country Status (1)

Country Link
CN (1) CN113220709B (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111061757A (en) * 2019-12-19 2020-04-24 用友网络科技股份有限公司 Database language conversion method and device, electronic equipment and storage medium
CN112015430A (en) * 2020-09-07 2020-12-01 平安国际智慧城市科技股份有限公司 JavaScript code translation method and device, computer equipment and storage medium
CN112527815A (en) * 2020-12-02 2021-03-19 平安医疗健康管理股份有限公司 Script migration method and device for database, computer equipment and storage medium

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111061757A (en) * 2019-12-19 2020-04-24 用友网络科技股份有限公司 Database language conversion method and device, electronic equipment and storage medium
CN112015430A (en) * 2020-09-07 2020-12-01 平安国际智慧城市科技股份有限公司 JavaScript code translation method and device, computer equipment and storage medium
CN112527815A (en) * 2020-12-02 2021-03-19 平安医疗健康管理股份有限公司 Script migration method and device for database, computer equipment and storage medium

Also Published As

Publication number Publication date
CN113220709A (en) 2021-08-06

Similar Documents

Publication Publication Date Title
US9619448B2 (en) Automated document revision markup and change control
CN112232074B (en) Entity relationship extraction method and device, electronic equipment and storage medium
CN110019291A (en) A kind of SQL analytic method and SQL resolver
US7664773B2 (en) Structured data storage method, structured data storage apparatus, and retrieval method
CN113051285B (en) SQL sentence conversion method, system, equipment and storage medium
US20160342628A1 (en) Textual query editor for graph databases that performs semantic analysis using extracted information
CN106874163B (en) Method and system for displaying software error code information
US20080092034A1 (en) Identifying and annotating shared hierarchical markup document trees
US8635242B2 (en) Processing queries on hierarchical markup data using shared hierarchical markup trees
WO2022100032A1 (en) System analysis visualization method and apparatus, electronic device, and computer readable storage medium
US9037553B2 (en) System and method for efficient maintenance of indexes for XML files
CN107943929B (en) Wrapper automatic generation method based on DOM tree abstraction
CN108241658A (en) A kind of logging mode finds method and system
JP2005190163A (en) Method, apparatus and program for retrieving structured data
CN104794244A (en) Method and device for realizing graph conversion based on MongoDB
CN113220709B (en) Grammar processing method, device, equipment and storage medium for operation database
CN110019306B (en) SQL statement searching method and system based on XML format file
CN108509187B (en) Method and system for automatically generating MIB function code of software platform
CN105468521B (en) A kind of semantic location of mistake method of pointer correlation based on subgraph search
US8719693B2 (en) Method for storing localized XML document values
JP2013218627A (en) Method and device for extracting information from structured document and program
CN113378544A (en) Text analysis method, text data acquisition method, device, medium and equipment
Chen et al. Incremental mining of frequent xml query patterns
CN114490928B (en) Implementation method, system, computer equipment and storage medium of semantic search
CN117807137A (en) Rule-based SQL (structured query language) to PromQL (PromQL) conversion method

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
GR01 Patent grant
GR01 Patent grant