CN111191106B - DSL construction method, system, electronic device and medium - Google Patents
DSL construction method, system, electronic device and medium Download PDFInfo
- Publication number
- CN111191106B CN111191106B CN201911395685.3A CN201911395685A CN111191106B CN 111191106 B CN111191106 B CN 111191106B CN 201911395685 A CN201911395685 A CN 201911395685A CN 111191106 B CN111191106 B CN 111191106B
- Authority
- CN
- China
- Prior art keywords
- dsl
- target
- law
- sub
- traversing
- 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
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/95—Retrieval from the web
- G06F16/953—Querying, e.g. by the use of web search engines
- G06F16/9532—Query formulation
Landscapes
- Engineering & Computer Science (AREA)
- Databases & Information Systems (AREA)
- Physics & Mathematics (AREA)
- Theoretical Computer Science (AREA)
- Mathematical Physics (AREA)
- Data Mining & Analysis (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Complex Calculations (AREA)
- Emergency Protection Circuit Devices (AREA)
- Stored Programmes (AREA)
Abstract
The invention discloses a DSL construction method, a system, electronic equipment and a medium, wherein the DSL construction method comprises the following steps: converting the target arithmetic expression into a target Token set; traversing the target Token set to convert to an inverse Polish; traversing the reverse Polish to build an operand stack, popping the first operand from the operand stack as the target DSL. The invention reduces the complexity of DSL construction.
Description
Technical Field
The present invention belongs to the technical field of DSL construction, and in particular, to a DSL construction method, system, electronic device, and medium.
Background
As one of the open source distributed search engines, the elastiscearch (a search server) has cluster deployment of different scales on internet enterprises of various scales, so that it has very active communities, and its use and mining has not stopped at a moment. The elastic search has a special Query DSL (Query expression). Because of the inherent differences between the elastomer search and traditional relational databases, elastomer search-SQL (a database) has limited supported functions, can only make simple logical queries, does not support join (a data type) types, and is an X-Pack (a plug-in) plug-in, increasing the complexity of deployment.
Disclosure of Invention
The invention aims to overcome the defect of high complexity of DSL construction in the prior art and provides a DSL construction method, a system, electronic equipment and a medium.
The invention solves the technical problems by the following technical scheme:
the invention provides a DSL construction method, which comprises the following steps:
converting the target arithmetic expression into a target Token (legal element) set;
traversing the target Token set to convert to an inverse Polish;
traversing the reverse Polish to build an operand stack, popping the first operand from the operand stack as the target DSL.
Preferably, the step of traversing the set of target Token to convert to an inverse polish formula comprises:
different types of target Token in the target Token set are identified, and the target Token is packaged into Function, parameter, operand objects.
Preferably, traversing the inverse Polish style to construct an operand stack includes:
judging whether the sub-query is performed, if the sub-query is performed, converting the reverse Polish formula into a form of a least term sum according to the distribution law, the combination law, the exchange law and the inversion law of the logic expression, carrying out exchange sequencing on each least term according to the attributes of the father and son documents, and constructing a sub-query DSL to generate a target DSL; if not a sub-query, a target DSL is built for each Operator object.
Preferably, the target DSL is Elasticsearch Query DSL.
The invention also provides a DSL construction system, which comprises a lexical analyzer, an inverse Polish converter and a grammar constructor;
the lexical analyzer is used for converting the target arithmetic expression into a target Token set;
the reverse Polish converter is used for traversing the target Token set to convert into a reverse Polish formula;
the grammar builder is used for traversing the reverse Polish formula to build an operand stack, and is used for popping a first operand from the operand stack as a target DSL.
Preferably, the reverse Poland-type converter is further configured to identify different types of target tokens in the set of target tokens, and to wrap the target tokens into Function, parameter, operator objects.
Preferably, the grammar constructor is further used for judging whether the grammar is sub-query, if so, converting the reverse Polish formula into the form of the sum of the least terms according to the distribution law, the combination law, the exchange law and the inversion law of the logic expression, carrying out exchange sequencing on each least term according to the attributes of the parent-child documents, and constructing sub-query DSL to generate the target DSL; if not a sub-query, a target DSL is built for each Operator object.
Preferably, the target DSL is Elasticsearch Query DSL.
The invention also provides an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the method of constructing DSL of the invention when executing the computer program.
The invention also provides a computer readable storage medium having stored thereon a computer program which when executed by a processor implements the steps of the method of constructing a DSL of the present invention.
The invention has the positive progress effects that: the invention reduces the complexity of DSL construction.
Drawings
Fig. 1 is a flow chart of a method of constructing a DSL of embodiment 1 of the present invention.
Fig. 2 is a schematic structural diagram of a DSL construction system according to embodiment 1 of the present invention.
Fig. 3 is a schematic structural diagram of an electronic device according to embodiment 3 of the present invention.
Detailed Description
The invention is further illustrated by means of the following examples, which are not intended to limit the scope of the invention.
Example 1
The present embodiment provides a method for constructing DSL. Referring to fig. 1, the construction method of the DSL includes the following steps:
step S101, converting the target arithmetic expression into a target Token set.
Step S102, traversing the target Token set to convert into an inverse Poland formula.
Step S103, traversing the reverse Polish formula to construct an operand stack, and popping the first operand from the operand stack as the target DSL.
In step S101, an arithmetic logic expression (generally, a character string) is parsed, and the arithmetic logic expression is divided into a collection of Token.
In step S102, different types of target Token in the target Token set are identified, and the target Token is packaged into a Function, parameter, operator object. During which the Function is calculated as a dynamic Parameter by Function Calculator. By converting the reverse Polish expression, the priority relation in the arithmetic logic expression is removed, and DSL construction is facilitated.
In step S103, judging whether the sub-query is performed, if so, converting the reverse polish formula into the form of the sum of the minimum terms according to the distribution law, the combination law, the exchange law and the inversion law of the logic expression, performing exchange sequencing on each minimum term according to the attributes of the parent-child documents, and constructing a sub-query DSL to generate a target DSL; if not a sub-query, a target DSL is built for each Operator object.
As an alternative embodiment, the target DSL is Elasticsearch Query DSL.
The construction method of DSL in this embodiment simplifies the construction of ElasticSearch Query DSL, and in most cases only needs to be given, for example: the following is carried out The construction of DSL can be completed by the arithmetic logic expression of (field 1= = x||field 2= y) & field3> z, thereby avoiding hard coding construction of DSL by developers, reducing development amount and improving development efficiency. On the other hand, non-technical staff such as business operation and the like can use the arithmetic logic expression to inquire the wanted data, so that technical staff such as development, operation and maintenance and the like are avoided, and the working efficiency is improved.
Example 2
The present embodiment provides a DSL building system. Referring to fig. 2, the DSL construction system includes a lexical analyzer (Lexer) 201, an inverse polish converter (Reserve Poland Parser) 202, and a grammar constructor (Builder) 203.
The lexical analyzer 201 is used to convert the target arithmetic expression into a target Token set. The inverse Poland-type converter 202 is used to traverse the target Token set to convert to an inverse Poland-type. The grammar builder 203 is operable to traverse the inverse Polish formula to build an operand stack and to pop the first operand from the operand stack as the target DSL.
In particular, the lexical analyzer 201 parses an arithmetic logic expression (typically a string) to divide the arithmetic logic expression into a collection of Token.
The inverse Polish converter 202 identifies different types of target tokens in the set of target tokens, wrapping the target tokens into Function, parameter, operator objects. During which the Function is calculated as a dynamic Parameter by Function Calculator. By converting the reverse Polish expression, the priority relation in the arithmetic logic expression is removed, and DSL construction is facilitated.
The grammar constructor 203 judges whether the sub-query is the sub-query, if the sub-query is the sub-query, the reverse polish formula is converted into the form of the sum of the least terms according to the distribution law, the combination law, the exchange law and the inversion law of the logic expression, the exchange ordering is carried out on each least term according to the attribute of the parent-child documents, and the sub-query DSL is constructed to generate the target DSL; if not a sub-query, a target DSL is built for each Operator object.
As an alternative embodiment, the target DSL is Elasticsearch Query DSL.
The DSL construction system of this embodiment simplifies the construction of ElasticSearch Query DSL, in most cases only given, for example: the following is carried out The construction of DSL can be completed by the arithmetic logic expression of (field 1= = x||field 2= y) & field3> z, thereby avoiding hard coding construction of DSL by developers, reducing development amount and improving development efficiency. On the other hand, non-technical staff such as business operation and the like can use the arithmetic logic expression to inquire the wanted data, so that technical staff such as development, operation and maintenance and the like are avoided, and the working efficiency is improved.
Example 3
Fig. 3 is a schematic structural diagram of an electronic device according to the present embodiment. The electronic device includes a memory, a processor, and a computer program stored on the memory and executable on the processor, which when executed implements the method of constructing DSL of embodiment 1. The electronic device 30 shown in fig. 3 is only an example and should not be construed as limiting the functionality and scope of use of embodiments of the present invention.
The electronic device 30 may be in the form of a general purpose computing device, which may be a server device, for example. Components of electronic device 30 may include, but are not limited to: the at least one processor 31, the at least one memory 32, a bus 33 connecting the different system components, including the memory 32 and the processor 31.
The bus 33 includes a data bus, an address bus, and a control bus.
The processor 31 executes various functional applications and data processing, such as the construction method of DSL of embodiment 1 of the present invention, by running a computer program stored in the memory 32.
The electronic device 30 may also communicate with one or more external devices 34 (e.g., keyboard, pointing device, etc.). Such communication may be through an input/output (I/O) interface 35. Also, model-generating device 30 may also communicate with one or more networks, such as a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network, such as the internet, via network adapter 36. As shown, network adapter 36 communicates with the other modules of model-generating device 30 via bus 33. It should be appreciated that although not shown in the figures, other hardware and/or software modules may be used in connection with the model-generating device 30, including, but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID (disk array) systems, tape drives, data backup storage systems, and the like.
It should be noted that although several units/modules or sub-units/modules of an electronic device are mentioned in the above detailed description, such a division is merely exemplary and not mandatory. Indeed, the features and functionality of two or more units/modules described above may be embodied in one unit/module in accordance with embodiments of the present invention. Conversely, the features and functions of one unit/module described above may be further divided into ones that are embodied by a plurality of units/modules.
Example 4
The present embodiment provides a computer readable storage medium having stored thereon a computer program which when executed by a processor implements the steps of the DSL build method of embodiment 1.
More specifically, among others, readable storage media may be employed including, but not limited to: portable disk, hard disk, random access memory, read only memory, erasable programmable read only memory, optical storage device, magnetic storage device, or any suitable combination of the foregoing.
In a possible embodiment, the invention may also be implemented in the form of a program product comprising program code for causing a terminal device to carry out the steps of the construction method of DSL implementing embodiment 1, when said program product is run on the terminal device.
Wherein the program code for carrying out the invention may be written in any combination of one or more programming languages, which program code may execute entirely on the user device, partly on the user device, as a stand-alone software package, partly on the user device and partly on the remote device or entirely on the remote device.
While specific embodiments of the invention have been described above, it will be appreciated by those skilled in the art that this is by way of example only, and the scope of the invention is defined by the appended claims. Various changes and modifications to these embodiments may be made by those skilled in the art without departing from the principles and spirit of the invention, but such changes and modifications fall within the scope of the invention.
Claims (6)
1. A method of constructing a DSL comprising the steps of:
converting the target arithmetic expression into a target Token set;
traversing the set of target Token to convert to an inverse polish formula;
traversing the reverse Polish formula to construct an operand stack, and popping a first operand from the operand stack as a target DSL;
the step of traversing the set of target Token to convert to an inverse polish formula comprises:
identifying different types of target Token in the target Token set, and packaging the target Token into Function, parameter, operator objects;
the step of traversing the inverse polish formula to construct an operand stack includes:
judging whether the sub-query is performed, if the sub-query is performed, converting the reverse Polish formula into a form of a least term sum according to a distribution law, a combination law, a switching law and an inversion law of a logic expression, performing switching sequencing on each least term according to attributes of parent-child documents, and constructing a sub-query DSL to generate the target DSL; if not, the target DSL is constructed for each of the Operator objects.
2. The method of constructing a DSL of claim 1 wherein the target DSL is Elasticsearch Query DSL.
3. A DSL construction system, which is characterized by comprising a lexical analyzer, an inverse Polish converter and a grammar constructor;
the lexical analyzer is used for converting the target arithmetic expression into a target Token set;
the inverse Poland type converter is used for traversing the target Token set to convert into an inverse Poland type;
the grammar constructor is used for traversing the reverse Polish formula to construct an operand stack and is used for popup of a first operand from the operand stack as a target DSL;
the reverse Polish converter is further used for identifying different types of target Token in the target Token set, and packaging the target Token into Function, parameter, operator objects;
the grammar constructor is also used for judging whether the grammar constructor is a sub-inquiry, if the grammar constructor is the sub-inquiry, converting the reverse Polish formula into a form of a least term sum according to a distribution law, a combination law, a switching law and an inversion law of a logic expression, carrying out switching sequencing on each least term according to attributes of a parent-child document, and constructing a sub-inquiry DSL so as to generate the target DSL; if not, constructing for each of the Operator objectsBy a means ofThe target DSL.
4. The DSL build system of claim 3 wherein the target DSL is Elasticsearch Query DSL.
5. An electronic 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 method of constructing DSL according to claim 1 or 2 when executing the computer program.
6. A computer readable storage medium having stored thereon a computer program, which when executed by a processor, implements the steps of the DSL construction method of claim 1 or 2.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201911395685.3A CN111191106B (en) | 2019-12-30 | 2019-12-30 | DSL construction method, system, electronic device and medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201911395685.3A CN111191106B (en) | 2019-12-30 | 2019-12-30 | DSL construction method, system, electronic device and medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111191106A CN111191106A (en) | 2020-05-22 |
CN111191106B true CN111191106B (en) | 2023-05-12 |
Family
ID=70711069
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201911395685.3A Active CN111191106B (en) | 2019-12-30 | 2019-12-30 | DSL construction method, system, electronic device and medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111191106B (en) |
Families Citing this family (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111767004B (en) * | 2020-06-30 | 2022-02-11 | 电子科技大学 | Digital oscilloscope mathematical operation processing method based on inverse Polish algorithm |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6314564B1 (en) * | 1997-11-17 | 2001-11-06 | Agere Systems Guardian Corp. | Method for resolving arbitrarily complex expressions at link-time |
CN104915194A (en) * | 2015-05-11 | 2015-09-16 | 南京国电南自美卓控制***有限公司 | Power failure data analysis formula editor based on arithmetic reverse polish algorithm |
CN106980619A (en) * | 2016-01-18 | 2017-07-25 | 北京国双科技有限公司 | Data query method and device |
CN108491207A (en) * | 2018-03-02 | 2018-09-04 | 平安科技(深圳)有限公司 | Expression processing method, apparatus, equipment and computer readable storage medium |
-
2019
- 2019-12-30 CN CN201911395685.3A patent/CN111191106B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6314564B1 (en) * | 1997-11-17 | 2001-11-06 | Agere Systems Guardian Corp. | Method for resolving arbitrarily complex expressions at link-time |
CN104915194A (en) * | 2015-05-11 | 2015-09-16 | 南京国电南自美卓控制***有限公司 | Power failure data analysis formula editor based on arithmetic reverse polish algorithm |
CN106980619A (en) * | 2016-01-18 | 2017-07-25 | 北京国双科技有限公司 | Data query method and device |
CN108491207A (en) * | 2018-03-02 | 2018-09-04 | 平安科技(深圳)有限公司 | Expression processing method, apparatus, equipment and computer readable storage medium |
Non-Patent Citations (5)
Title |
---|
Springer,Berlin,Heidelberg.Deductive program development:Evaluation in reverse Polish notation as an example.《Method of Programming》.2005,第77-99页. * |
周丰.逆波兰表达式及其算法实现.武汉交通职业学院学报.2004,第62-65页. * |
易昌中 ; .一个基于JAVA语言的编译器设计.宜春学院学报.2017,第55-57页. * |
李广强.基于转换的程序分析技术的研究与应用.中国优秀硕士学位论文全文数据库.2007,第I138-159页. * |
沈祖梁.FORTH入门(上).《计算机工程与应用》.1985,第35-37页. * |
Also Published As
Publication number | Publication date |
---|---|
CN111191106A (en) | 2020-05-22 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
EP2608066B1 (en) | Many core algorithms for in-memory column store databases | |
US8239847B2 (en) | General distributed reduction for data parallel computing | |
US7877370B2 (en) | Systems and methods for data storage and retrieval using algebraic relations composed from query language statements | |
US9110706B2 (en) | General purpose distributed data parallel computing using a high level language | |
US8601474B2 (en) | Resuming execution of an execution plan in a virtual machine | |
US20120066205A1 (en) | Query Compilation Optimization System and Method | |
US9684493B2 (en) | R-language integration with a declarative machine learning language | |
JP5791149B2 (en) | Computer-implemented method, computer program, and data processing system for database query optimization | |
JP5113157B2 (en) | System and method for storing and retrieving data | |
US10268461B2 (en) | Global data flow optimization for machine learning programs | |
CN115809063A (en) | Storage process compiling method, system, electronic equipment and storage medium | |
CN111191106B (en) | DSL construction method, system, electronic device and medium | |
Kostenetskii et al. | Simulation of hierarchical multiprocessor database systems | |
CN112114817B (en) | COBOL language-based data dictionary field information acquisition method and device | |
CN113326261A (en) | Data blood relationship extraction method and device and electronic equipment | |
Rompf et al. | A SQL to C compiler in 500 lines of code | |
Sinthong et al. | AFrame: Extending DataFrames for large-scale modern data analysis (Extended Version) | |
US11874830B2 (en) | Efficient job writing for database member | |
CN103809915A (en) | Read-write method and device of magnetic disk files | |
CN115809294A (en) | Rapid ETL method based on Spark SQL temporary view | |
Liu et al. | Integrating FPGA-based hardware acceleration with relational databases | |
CN112860233A (en) | Target syntax tree generation method and related equipment | |
CN108052522B (en) | Method and system for dynamically optimizing OLAP pre-calculation model | |
US8495033B2 (en) | Data processing | |
CN117251472B (en) | Cross-source data processing method, device, equipment and storage medium |
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 |