WO2023045054A1 - Structured query statement generation method and apparatus, and computer device - Google Patents

Structured query statement generation method and apparatus, and computer device Download PDF

Info

Publication number
WO2023045054A1
WO2023045054A1 PCT/CN2021/131748 CN2021131748W WO2023045054A1 WO 2023045054 A1 WO2023045054 A1 WO 2023045054A1 CN 2021131748 W CN2021131748 W CN 2021131748W WO 2023045054 A1 WO2023045054 A1 WO 2023045054A1
Authority
WO
WIPO (PCT)
Prior art keywords
information
structured
execution
statement
database
Prior art date
Application number
PCT/CN2021/131748
Other languages
French (fr)
Chinese (zh)
Inventor
孙岩
盛浩
孙迁
张光淡
华有军
邰娟
Original Assignee
苏宁易购集团股份有限公司
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 苏宁易购集团股份有限公司 filed Critical 苏宁易购集团股份有限公司
Publication of WO2023045054A1 publication Critical patent/WO2023045054A1/en

Links

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/245Query processing
    • G06F16/2453Query optimisation
    • 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/245Query processing
    • G06F16/2455Query execution

Definitions

  • the present application relates to the technical field of big data, and in particular to a method, device, computer equipment and storage medium for generating structured query statements.
  • the manual writing method makes the structured query statements repetitive and complicated, which takes a lot of time for trial and error and verification, does not support the replacement of dynamic parameters, and the used statements cannot be saved and consulted conveniently; at the same time, it is impossible to Batch processing of structured query statements has poor continuity. After outputting the result of a statement, it is necessary to manually add the next statement. It is impossible to efficiently manage each statement, and the work efficiency is low.
  • a method for generating a structured query statement comprising:
  • the above-mentioned acquisition of information to be queried includes:
  • the second information is used as the information to be queried.
  • it also includes:
  • the user is prompted to make a new selection.
  • the above-mentioned globally unique ID is generated according to the structured execution statement; and after storing the structured execution statement and the ID in the database relational table, it also includes:
  • the structured execution statement corresponding to the task instance is extracted from the database relational table for execution, and the obtained execution result is output to the database result table, and the task instance disappears automatically after the execution is completed.
  • the above-mentioned structured execution statement corresponding to the task instance is extracted from the database relational table for execution, and the obtained execution result is output to the database result table, and the task instance disappears automatically after the execution is completed, including :
  • the ID, execution result and success status are stored in the database result table and displayed on the operation interface;
  • the ID, failure status and error log are stored in the database result table and displayed on the operation interface.
  • it also includes:
  • the above-mentioned formatting of the structured execution statement includes:
  • a device for generating a structured query statement includes:
  • the obtaining module is used to obtain the information to be queried and the preset structured query statement template
  • the preprocessing module is used to replace the dynamic information in the preset structured query statement template with the information to be queried, and generate a structured execution statement;
  • the generating module is used for generating a globally unique ID according to the structured execution statement; and storing the structured execution statement and the ID in a relational table of the database.
  • a computer device including a memory, a processor, and a computer program stored on the memory and operable on the processor.
  • the processor executes the computer program, the following steps are implemented:
  • a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
  • the method, device, computer equipment, and storage medium for generating the above-mentioned structured query statement firstly, by obtaining the information to be queried and the preset structured query statement template, the dynamic information in the preset structured query statement template is replaced For the information to be queried, a structured execution statement is generated; then, a globally unique ID is generated according to the structured execution statement; finally, the structured execution statement and the ID are stored in a database relational table.
  • the above process does not need to be written manually, and the structured query statement template can be obtained directly, and a new structured execution statement can be generated by replacing the dynamic parameters in the structured query statement template, so as to save a lot of time and improve work efficiency;
  • the user can directly implement the execution of the structured execution statement and query the results according to the ID, so as to achieve the effect of conveniently saving and consulting the structured execution statement, and realize the efficient management of the structured execution statement.
  • Fig. 1 is an application environment diagram of a method for generating a structured query statement in an embodiment
  • Fig. 2 is a schematic flow chart of a method for generating a structured query statement in an embodiment
  • Fig. 3 is a structural block diagram of a device for generating a structured query statement in an embodiment
  • Figure 4 is an internal block diagram of a computer device in one embodiment.
  • a method for generating a structured query statement provided in this application can be applied to the application environment shown in FIG. 1 .
  • the terminal 102 communicates with the server 104 through the network.
  • the server 104 obtains the information to be queried and the preset structured query statement template; the server replaces the dynamic information in the preset structured query statement template with the information to be queried to generate a structured execution statement; and generates a global query statement according to the structured execution statement Unique ID; and store the structured execution statement and ID in the relational table of the database.
  • the terminal 102 can be, but not limited to, various personal computers, notebook computers, tablet computers and other devices, and the server 104 can be realized by an independent server or a server cluster composed of multiple servers.
  • a method for generating a structured query statement is provided.
  • the method is applied to the terminal in FIG. 1 as an example for illustration, including the following steps:
  • Step 202 obtaining the information to be queried and a preset structured query statement template.
  • the information to be queried includes but not limited to database name, table name, field and other information;
  • the preset structured query statement template refers to the structured query statement saved in the query database in advance.
  • data developers often need to compare and analyze data forms of different offline tables during requirements development, data migration, or grayscale testing. At this time, they need to obtain the information to be queried, that is, the corresponding database name, Information such as table names and fields; at the same time, the server obtains the corresponding structured query statement template from the query database.
  • Step 204 replacing the dynamic information in the preset structured query statement template with the information to be queried to generate a structured execution statement.
  • structured query statement is a kind of database query and programming language, which is used to access and query data, etc.; dynamic information refers to dynamic parameters that can be replaced, and the server will preset the dynamic information in the structured query statement template.
  • the information is replaced with the information to be queried that we need to compare to generate a new structured query statement, that is, a structured execution statement, which is a complete structured query statement.
  • Step 206 generate a globally unique ID according to the structured execution statement; and store the structured execution statement and the ID in the relational table of the database.
  • this ID is globally unique, each structured execution statement and each ID are in one-to-one correspondence, without duplication; and, store this ID and the structured execution statement in the database In the relational table; in this way, later users can directly realize the execution of the structured execution statement and the query of the result according to the ID.
  • the database includes the Hive data warehouse and relational database
  • the relational database includes the mainstream MySQL database and DB2 database. How many types of tables are there in a relational database?
  • a database relational table refers to a table used to store the correspondence between structured execution statements and IDs.
  • the method, device, computer equipment, and storage medium for generating the above-mentioned structured query statement firstly, by obtaining the information to be queried and the preset structured query statement template, the dynamic information in the preset structured query statement template is replaced For the information to be queried, a structured execution statement is generated; then, a globally unique ID is generated according to the structured execution statement; finally, the structured execution statement and the ID are stored in a database relational table.
  • the above process does not need to be written manually, and the structured query statement template can be obtained directly, and a new structured execution statement can be generated by replacing the dynamic parameters in the structured query statement template, so as to save a lot of time and improve work efficiency;
  • the user can directly implement the execution of the structured execution statement and query the results according to the ID, so as to achieve the effect of conveniently saving and consulting the structured execution statement, and realize the efficient management of the structured execution statement .
  • the above-mentioned acquisition of information to be queried includes the following steps:
  • the first information is obtained from the metadata.
  • the metadata is a description of the data resource, and the first information includes the library name, table name, and field name selected by the user. Carry out a legality test on the first information, and set the first information that passes the legality test as the second information. This operation is mainly for the preliminary check of the first information selected by the user, because if the first information selected by the user If it is illegal, it means that the structured execution statement generated later is wrong, and there is no meaning of generation.
  • the server receives the first information selected by the user, and compares the first information with the information in the specified database.
  • the specified database here refers to the database storing metadata, and the information in the metadata is obtained from the specified database. Therefore, it indirectly indicates that the first information is derived from the specified database.
  • the first information exists in the specified database, it is determined that the first information is legal, that is, the first information is real, and the first information that passes the legality test is set as the second information, and the second information is used as the query information.
  • the metadata information is not a real database, it is obtained from the specified database, and will not be updated synchronously with the data in the specified database, and there may be delays in updating relative to the specified database Therefore, it is necessary to compare the first information selected by the user with the information in the specified database.
  • the first information does not exist in the designated database, it is judged that the first information is illegal, and the user is prompted to choose again, which means that there is a situation that the update is not timely, and the data to be analyzed does not exist in the designated database, so the user needs to be prompted Make your selection again.
  • the structured execution statement needs to be formatted and grammatically checked, so that the structured execution statement complies with the syntax standard of the relational database.
  • the structured execution statement when the structured execution statement is formatted, it includes replacing blank characters in the structured execution statement with a single space and unifying the structured execution statement into uppercase or lowercase letters, so that the structured execution statement is unified;
  • the syntax proofreading of the structured execution statement includes error correction of special characters and reserved words in the structured execution statement, so as to ensure the correctness and executability of the structured execution statement.
  • a globally unique ID is generated according to the structured execution statement; and after storing the structured execution statement and the ID in the relational table of the database, the following steps are further included:
  • each ID corresponds to an independent task
  • the task instance will create a spark task according to the passed ID
  • the server extracts the structured execution corresponding to the task instance from the database relational table. Statements are executed, and the obtained execution results are output to the database result table, and each task instance disappears automatically after execution, and multiple task instances can be performed simultaneously.
  • the database result table here is similar to the database relationship table, both of which are in the same database, but belong to different types of tables and are used to store different types of data.
  • the ID, execution result, and success status are stored in the database result table.
  • the ID, execution result, and successful status are in one-to-one correspondence It is saved in the database result table, which is convenient for the staff to view it later, and the execution result is echoed to the operation interface, so that the staff can see the current running result;
  • the execution of the task instance fails the ID, failure status and The error log is stored in the database result table, because there is no execution result when the task execution fails, then the failure log will be generated and stored in the database result table together with the failure status and ID, so as to remind the staff later to avoid Make the same type of mistake, and echo the error log to the operation interface, so that the staff can see the current execution status; of course, the server also needs to keep the data in the database relationship table and database result table updated in real time.
  • the user operation interface initiates a data display request to the server, and the server processes the request to obtain the data to be displayed from the database result table and returns it to the user operation interface.
  • the user calls the graph visualization library on the user operation interface according to the terminal’s graph visualization library.
  • the chart style specified in the library is used to assemble the data to realize the visual display of the data.
  • the above operations support real-time batch execution of multiple structured execution statements, and provide storage and management of execution statements, execution status, and execution results, which can improve the processing efficiency of comparison and analysis of different offline table data forms, and reduce data development.
  • the problems and exceptions in the database can improve the quality of data development; at the same time, the visual display of the data in the database result table solves the problems of unintuitive display of data in the database result table and inconvenient unified viewing.
  • steps in the flow chart of FIG. 2 are displayed sequentially according to the arrows, these steps are not necessarily executed sequentially in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least some of the steps in FIG. 2 may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but may be executed at different times. The execution of these sub-steps or stages The order is not necessarily performed sequentially, but may be performed alternately or alternately with at least a part of other steps or sub-steps or stages of other steps.
  • an apparatus for generating a structured query statement including: an acquisition module 302, a preprocessing module 304, and a generation module 306, wherein:
  • the acquiring module 302 is configured to acquire the information to be queried and a preset structured query statement template.
  • the preprocessing module 304 is configured to replace the dynamic information in the preset structured query statement template with the information to be queried, and generate a structured execution statement.
  • the generating module 306 is configured to generate a globally unique ID according to the structured execution statement; and store the structured execution statement and the ID in a relational table of the database.
  • the acquisition module 302 is also specifically configured to:
  • the first information is obtained from the metadata; the legality test is performed on the first information, and the first information that passes the legality test is set as the second information; and the second information is used as the information to be queried.
  • the above-mentioned device for generating structured query sentences further includes a legality judgment module (not shown in the figure), which is used to receive the first information selected by the user; combine the first information and The information in the designated database is compared, wherein the metadata is obtained from the designated database; when the first information exists in the designated database, it is determined that the first information is legal; when the first information does not exist in the designated database, It is determined that the first information is invalid, and the user is prompted to make a new selection.
  • a legality judgment module (not shown in the figure), which is used to receive the first information selected by the user; combine the first information and The information in the designated database is compared, wherein the metadata is obtained from the designated database; when the first information exists in the designated database, it is determined that the first information is legal; when the first information does not exist in the designated database, It is determined that the first information is invalid, and the user is prompted to make a new selection.
  • the preprocessing module 304 is also used to:
  • Formatting and grammar proofreading of structured execution statements, and formatting of structured execution statements including: replacing blank characters in structured execution statements with single spaces and unifying structured execution statements into uppercase letters or lowercase Letters; grammar proofreading for structured execution statements, including: error correction for special characters and reserved words in structured execution statements.
  • the generation module 306 is also used to:
  • Each module in the above-mentioned device for generating structured query statements can be fully or partially realized by software, hardware and a combination thereof.
  • the above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, and can also be stored in the memory of the computer device in the form of software, so that the processor can invoke and execute the corresponding operations of the above-mentioned modules.
  • a computer device is provided.
  • the computer device may be a server, and its internal structure may be as shown in FIG. 4 .
  • the computer device includes a processor, memory, network interface and database connected by a system bus. Wherein, the processor of the computer device is used to provide calculation and control capabilities.
  • the memory of the computer device includes a non-volatile storage medium and an internal memory.
  • the non-volatile storage medium stores an operating system, computer programs and databases.
  • the internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium.
  • the database of the computer device is used to store the relationship between the ID and the structured execution statement and the data of the execution result.
  • the network interface of the computer device is used to communicate with an external terminal via a network connection.
  • FIG. 4 is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation to the computer equipment on which the solution of the application is applied.
  • the specific computer equipment can be More or fewer components than shown in the figures may be included, or some components may be combined, or have a different arrangement of components.
  • a computer device including a memory, a processor, and a computer program stored on the memory and operable on the processor.
  • the processor executes the computer program, the following steps are implemented:
  • the first information is obtained from the metadata; the legality test is performed on the first information, and the first information that passes the legality test is set as the second information; and the second information is used as the information to be queried.
  • the server receives the first information selected by the user; compares the first information with the information in the specified database, wherein the metadata is obtained from the specified database; when the first information exists in the specified database, determines the first information Legal; when the first information does not exist in the specified database, it is judged that the first information is not legal, and the user is prompted to choose again.
  • Grammatical proofreading for structured execution statements including: error correction for special characters and reserved words in structured execution statements.
  • the processor executes the computer program to realize the above-mentioned steps of generating a globally unique ID according to the structured execution statement; and storing the structured execution statement and the ID in the database relational table, it also includes:
  • the processor executes the computer program, it also includes:
  • a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
  • the server receives the first information selected by the user; compares the first information with the information in the specified database, wherein the metadata is obtained from the specified database; when the first information exists in the specified database, determines the first information Legal; when the first information does not exist in the specified database, it is judged that the first information is not legal, and the user is prompted to choose again.
  • Grammatical proofreading for structured execution statements including: error correction for special characters and reserved words in structured execution statements.
  • the computer program after the computer program is executed by the processor to generate the globally unique ID according to the structured execution statement; and store the structured execution statement and the ID in the database relational table, it also includes:
  • Nonvolatile memory can include read only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory.
  • Volatile memory can include random access memory (RAM) or external cache memory.
  • RAM random access memory
  • RAM is available in many forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchronous Chain Synchlink DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

Abstract

A structured query statement generation method and apparatus, and a computer device and storage medium. The method comprises: acquiring information to be queried and a preset structured query statement template (202); replacing dynamic information in the preset structured query statement template with the information to be queried, and generating a structured execution statement (204); and generating a globally unique ID according to the structured execution statement, and storing the structured execution statement and the ID in a database relationship table (206). By means of the method, the replacement of a dynamic parameter can be realized, so as to generate a new structured execution statement, thereby achieving the effects of saving a lot of time and improving the operation efficiency.

Description

结构化查询语句的生成方法、装置和计算机设备Method, device and computer equipment for generating structured query statement 技术领域technical field
本申请涉及大数据技术领域,尤其是涉及一种结构化查询语句的生成方法、装置、计算机设备和存储介质。The present application relates to the technical field of big data, and in particular to a method, device, computer equipment and storage medium for generating structured query statements.
背景技术Background technique
随着大数据技术领域的发展,数据开发人员在需求开发,数据迁移或灰度测试等阶段,经常需要对不同离线表进行数据形态的对比和分析,通过数据结果中的偏差和异常,发现数据处理逻辑中的问题。With the development of big data technology, data developers often need to compare and analyze data forms of different offline tables during requirements development, data migration or grayscale testing, and find data deviations and anomalies in data results. Deal with problems in logic.
对于如何获取数据结果,从而发现数据处理逻辑中存在的缺陷这一问题,传统的技术方案是通过手工编写结构化查询语句,再执行,实现对数据结果的获取。For the problem of how to obtain data results and discover defects in data processing logic, the traditional technical solution is to manually write structured query statements and execute them to obtain data results.
技术问题technical problem
然而,采用人工编写的方式,使得结构化查询语句重复繁杂需要消耗大量的时间来进行试错和校验、不支持动态参数的替换,且使用过的语句无法便捷的保存和查阅;同时,无法对结构化查询语句进行批处理,持续性差,输出完一个语句的结果后,需要人工手动添加下一个语句才可以,无法对各个语句进行高效的管理,工作效率低。However, the manual writing method makes the structured query statements repetitive and complicated, which takes a lot of time for trial and error and verification, does not support the replacement of dynamic parameters, and the used statements cannot be saved and consulted conveniently; at the same time, it is impossible to Batch processing of structured query statements has poor continuity. After outputting the result of a statement, it is necessary to manually add the next statement. It is impossible to efficiently manage each statement, and the work efficiency is low.
技术解决方案technical solution
基于此,有必要针对上述技术问题,提供一种结构化查询语句的生成方法、装置、计算机设备和存储介质。Based on this, it is necessary to provide a method, device, computer equipment, and storage medium for generating structured query statements to address the above technical problems.
一方面,提供一种结构化查询语句的生成方法,该方法包括:On the one hand, a method for generating a structured query statement is provided, the method comprising:
获取待查询信息和预置的结构化查询语句模板;Obtain the information to be queried and the preset structured query statement template;
将预置的结构化查询语句模板中的动态信息替换为待查询信息,生成结构化执行语句;Replace the dynamic information in the preset structured query statement template with the information to be queried to generate a structured execution statement;
根据结构化执行语句生成全局唯一ID;并将结构化执行语句和ID存入数据库关系表中。Generate a globally unique ID according to the structured execution statement; and store the structured execution statement and the ID in the database relational table.
在其中一个实施例中,上述的获取待查询信息包括: In one of the embodiments, the above-mentioned acquisition of information to be queried includes:
从元数据中获取第一信息; obtain the first information from the metadata;
对第一信息进行合法性测试,并将合法性测试通过的第一信息设置为第二信息;performing a legality test on the first information, and setting the first information that passes the legality test as the second information;
将第二信息作为待查询信息。The second information is used as the information to be queried.
在其中一个实施例中,还包括:In one of the embodiments, it also includes:
接收用户选择的第一信息;Receive the first information selected by the user;
将第一信息和指定数据库中的信息进行比对,其中,元数据是从指定数据库中获得的;comparing the first information with information in a specified database, wherein the metadata is obtained from the specified database;
在第一信息存在于指定数据库中时,判定第一信息合法;When the first information exists in the specified database, it is determined that the first information is legal;
在第一信息不存在于指定数据库中时,判定第一信息不合法,并提示用户重新选择。When the first information does not exist in the specified database, it is determined that the first information is invalid, and the user is prompted to make a new selection.
在其中一个实施例中,上述的根据结构化执行语句生成全局唯一ID;并将结构化执行语句和ID存入数据库关系表中之后,还包括: In one of the embodiments, the above-mentioned globally unique ID is generated according to the structured execution statement; and after storing the structured execution statement and the ID in the database relational table, it also includes:
根据ID创建任务实例;Create task instance according to ID;
从数据库关系表中提取对应于任务实例的结构化执行语句进行执行,并将获得的执行结果输出到数据库结果表中,且任务实例执行完成之后自动消失。The structured execution statement corresponding to the task instance is extracted from the database relational table for execution, and the obtained execution result is output to the database result table, and the task instance disappears automatically after the execution is completed.
在其中一个实施例中,上述的从数据库关系表中提取对应于任务实例的结构化执行语句进行执行,并将获得的执行结果输出到数据库结果表中,且任务实例执行完成之后自动消失,包括:In one of the embodiments, the above-mentioned structured execution statement corresponding to the task instance is extracted from the database relational table for execution, and the obtained execution result is output to the database result table, and the task instance disappears automatically after the execution is completed, including :
在任务实例执行成功时,将ID、执行结果以及成功状态存入数据库结果表中,并回显于操作界面;When the task instance is successfully executed, the ID, execution result and success status are stored in the database result table and displayed on the operation interface;
在任务实例执行失败时,将ID、失败状态以及报错日志存入数据库结果表中,并回显于操作界面。When the execution of the task instance fails, the ID, failure status and error log are stored in the database result table and displayed on the operation interface.
在其中一个实施例中,还包括:In one of the embodiments, it also includes:
对结构化执行语句进行格式化处理和语法校对。Perform formatting and grammar proofreading on structured execution statements.
在其中一个实施例中,上述的对结构化执行语句进行格式化处理,包括:In one of the embodiments, the above-mentioned formatting of the structured execution statement includes:
将结构化执行语句中的空白字符替换为单个空格以及将结构化执行语句统一为大写字母或者小写字母;Replace the blank characters in the structured execution statement with a single space and unify the structured execution statement into uppercase or lowercase letters;
对结构化执行语句进行语法校对,包括:Syntax proofreading of structured execution statements, including:
对结构化执行语句中的特殊字符以及保留字进行错误纠正。Error correction for special characters and reserved words in structured execution statements.
另一方面,提供了一种结构化查询语句的生成装置,该装置包括:On the other hand, a device for generating a structured query statement is provided, and the device includes:
获取模块,用于获取待查询信息和预置的结构化查询语句模板;The obtaining module is used to obtain the information to be queried and the preset structured query statement template;
预处理模块,用于将预置的结构化查询语句模板中的动态信息替换为待查询信息,生成结构化执行语句;The preprocessing module is used to replace the dynamic information in the preset structured query statement template with the information to be queried, and generate a structured execution statement;
生成模块,用于根据结构化执行语句生成全局唯一ID;并将结构化执行语句和ID存入数据库关系表中。The generating module is used for generating a globally unique ID according to the structured execution statement; and storing the structured execution statement and the ID in a relational table of the database.
再一方面,提供了一种计算机设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,处理器执行计算机程序时实现以下步骤:In yet another aspect, a computer device is provided, including a memory, a processor, and a computer program stored on the memory and operable on the processor. When the processor executes the computer program, the following steps are implemented:
获取待查询信息和预置的结构化查询语句模板;Obtain the information to be queried and the preset structured query statement template;
将预置的结构化查询语句模板中的动态信息替换为待查询信息,生成结构化执行语句;Replace the dynamic information in the preset structured query statement template with the information to be queried to generate a structured execution statement;
根据结构化执行语句生成全局唯一ID;并将结构化执行语句和ID存入数据库关系表中。Generate a globally unique ID according to the structured execution statement; and store the structured execution statement and the ID in the database relational table.
又一方面,提供了一种计算机可读存储介质,其上存储有计算机程序,计算机程序被处理器执行时实现以下步骤:In yet another aspect, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
获取待查询信息和预置的结构化查询语句模板;Obtain the information to be queried and the preset structured query statement template;
将预置的结构化查询语句模板中的动态信息替换为待查询信息,生成结构化执行语句;Replace the dynamic information in the preset structured query statement template with the information to be queried to generate a structured execution statement;
根据结构化执行语句生成全局唯一ID;并将结构化执行语句和ID存入数据库关系表中。Generate a globally unique ID according to the structured execution statement; and store the structured execution statement and the ID in the database relational table.
有益效果Beneficial effect
上述一种结构化查询语句的生成方法、装置、计算机设备和存储介质,首先,通过获取待查询信息和预置的结构化查询语句模板,将预置的结构化查询语句模板中的动态信息替换为待查询信息,生成结构化执行语句;然后,根据结构化执行语句生成全局唯一ID;最后,并将结构化执行语句和ID存入数据库关系表中。上述过程不需要再进行手工撰写,可以直接获取结构化查询语句模板,通过将结构化查询语句模板中的动态参数替换生成新的结构化执行语句,达到节省大量时间,且提高工作效率的效果;同时,后期用户可以直接根据ID实现对结构化执行语句的执行和结果的查询,达到方便对结构化执行语句进行保存和查阅的效果,且实现对结构化执行语句的高效管理。The method, device, computer equipment, and storage medium for generating the above-mentioned structured query statement, firstly, by obtaining the information to be queried and the preset structured query statement template, the dynamic information in the preset structured query statement template is replaced For the information to be queried, a structured execution statement is generated; then, a globally unique ID is generated according to the structured execution statement; finally, the structured execution statement and the ID are stored in a database relational table. The above process does not need to be written manually, and the structured query statement template can be obtained directly, and a new structured execution statement can be generated by replacing the dynamic parameters in the structured query statement template, so as to save a lot of time and improve work efficiency; At the same time, in the later stage, the user can directly implement the execution of the structured execution statement and query the results according to the ID, so as to achieve the effect of conveniently saving and consulting the structured execution statement, and realize the efficient management of the structured execution statement.
附图说明Description of drawings
图1为一个实施例中一种结构化查询语句的生成方法的应用环境图;Fig. 1 is an application environment diagram of a method for generating a structured query statement in an embodiment;
图2为一个实施例中一种结构化查询语句的生成方法的流程示意图;Fig. 2 is a schematic flow chart of a method for generating a structured query statement in an embodiment;
图3为一个实施例中一种结构化查询语句的生成装置的结构框图;Fig. 3 is a structural block diagram of a device for generating a structured query statement in an embodiment;
图4为一个实施例中计算机设备的内部结构图。Figure 4 is an internal block diagram of a computer device in one embodiment.
本发明的实施方式Embodiments of the present invention
为了使本申请的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。In order to make the purpose, technical solution and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described here are only used to explain the present application, and are not intended to limit the present application.
本申请提供的一种结构化查询语句的生成方法,可以应用于如图1所示的应用环境中。其中,终端102通过网络与服务器104通过网络进行通信。服务器104获取待查询信息和预置的结构化查询语句模板;服务器将预置的结构化查询语句模板中的动态信息替换为待查询信息,生成结构化执行语句;且根据结构化执行语句生成全局唯一ID;并将结构化执行语句和ID存入数据库关系表中。其中,终端102可以但不限于是各种个人计算机、笔记本电脑、平板电脑等设备,服务器104可以用独立的服务器或者是多个服务器组成的服务器集群来实现。A method for generating a structured query statement provided in this application can be applied to the application environment shown in FIG. 1 . Wherein, the terminal 102 communicates with the server 104 through the network. The server 104 obtains the information to be queried and the preset structured query statement template; the server replaces the dynamic information in the preset structured query statement template with the information to be queried to generate a structured execution statement; and generates a global query statement according to the structured execution statement Unique ID; and store the structured execution statement and ID in the relational table of the database. Wherein, the terminal 102 can be, but not limited to, various personal computers, notebook computers, tablet computers and other devices, and the server 104 can be realized by an independent server or a server cluster composed of multiple servers.
在一个实施例中,如图2所示,提供了一种结构化查询语句的生成方法,以该方法应用于图1中的终端为例进行说明,包括以下步骤:In one embodiment, as shown in FIG. 2, a method for generating a structured query statement is provided. The method is applied to the terminal in FIG. 1 as an example for illustration, including the following steps:
步骤202,获取待查询信息和预置的结构化查询语句模板。Step 202, obtaining the information to be queried and a preset structured query statement template.
其中,待查询信息包括但不限于库名、表名和字段等信息;预置的结构化查询语句模板是指预先保存到查询数据库中的结构化查询语句。Wherein, the information to be queried includes but not limited to database name, table name, field and other information; the preset structured query statement template refers to the structured query statement saved in the query database in advance.
具体地,数据开发人员在需求开发,数据迁移或灰度测试等阶段,经常需要对不同离线表进行数据形态的对比和分析,这时,就需要获取到待查询信息,即对应的库名、表名以及字段等信息;同时,服务器从查询数据库中获取对应的结构化查询语句模板。Specifically, data developers often need to compare and analyze data forms of different offline tables during requirements development, data migration, or grayscale testing. At this time, they need to obtain the information to be queried, that is, the corresponding database name, Information such as table names and fields; at the same time, the server obtains the corresponding structured query statement template from the query database.
步骤204,将预置的结构化查询语句模板中的动态信息替换为待查询信息,生成结构化执行语句。Step 204, replacing the dynamic information in the preset structured query statement template with the information to be queried to generate a structured execution statement.
其中,结构化查询语句是一种数据库查询和程序设计语言,用于存取和查询数据等;动态信息是指可以被替换掉的动态参数,服务器将预置的结构化查询语句模板中的动态信息替换为我们需要对其进行比对的待查询信息,生成新的结构化查询语句,即结构化执行语句,此结构化执行语句是完整的结构化查询语句。Among them, structured query statement is a kind of database query and programming language, which is used to access and query data, etc.; dynamic information refers to dynamic parameters that can be replaced, and the server will preset the dynamic information in the structured query statement template. The information is replaced with the information to be queried that we need to compare to generate a new structured query statement, that is, a structured execution statement, which is a complete structured query statement.
步骤206,根据结构化执行语句生成全局唯一ID;并将结构化执行语句和ID存入数据库关系表中。Step 206, generate a globally unique ID according to the structured execution statement; and store the structured execution statement and the ID in the relational table of the database.
根据每个结构化执行语句生成ID,此ID是全局唯一的,每个结构化执行语句和每个ID是一一对应的,没有重复的;并且,将此ID和结构化执行语句存入数据库关系表中;这样,后期用户可以直接根据ID实现对结构化执行语句的执行和结果的查询。Generate an ID based on each structured execution statement, this ID is globally unique, each structured execution statement and each ID are in one-to-one correspondence, without duplication; and, store this ID and the structured execution statement in the database In the relational table; in this way, later users can directly realize the execution of the structured execution statement and the query of the result according to the ID.
其中,数据库包括Hive数据仓库和关系型数据库,关系型数据库包括主流的MySQL数据库和DB2数据库。关系型数据库中会有多好类型的表,数据库关系表是指用于存储结构化执行语句和ID之间对应关系的表。Among them, the database includes the Hive data warehouse and relational database, and the relational database includes the mainstream MySQL database and DB2 database. How many types of tables are there in a relational database? A database relational table refers to a table used to store the correspondence between structured execution statements and IDs.
上述一种结构化查询语句的生成方法、装置、计算机设备和存储介质,首先,通过获取待查询信息和预置的结构化查询语句模板,将预置的结构化查询语句模板中的动态信息替换为待查询信息,生成结构化执行语句;然后,根据结构化执行语句生成全局唯一ID;最后,并将结构化执行语句和ID存入数据库关系表中。上述过程不需要再进行手工撰写,可以直接获取结构化查询语句模板,通过将结构化查询语句模板中的动态参数替换生成新的结构化执行语句,达到节省大量时间,且提高工作效率的效果;同时,后期用户可以直接根据ID实现对结构化执行语句的执行和结果的查询,达到方便对结构化执行语句进行保存和查阅的效果,且实现对结构化执行语句的高效管理 The method, device, computer equipment, and storage medium for generating the above-mentioned structured query statement, firstly, by obtaining the information to be queried and the preset structured query statement template, the dynamic information in the preset structured query statement template is replaced For the information to be queried, a structured execution statement is generated; then, a globally unique ID is generated according to the structured execution statement; finally, the structured execution statement and the ID are stored in a database relational table. The above process does not need to be written manually, and the structured query statement template can be obtained directly, and a new structured execution statement can be generated by replacing the dynamic parameters in the structured query statement template, so as to save a lot of time and improve work efficiency; At the same time, in the later stage, the user can directly implement the execution of the structured execution statement and query the results according to the ID, so as to achieve the effect of conveniently saving and consulting the structured execution statement, and realize the efficient management of the structured execution statement .
在其中一个实施例中,上述的获取待查询信息,包括如下步骤:In one of the embodiments, the above-mentioned acquisition of information to be queried includes the following steps:
从元数据中获取第一信息,元数据是对数据资源的描述,第一信息包括用户选取的库名、表名以及字段名等。对第一信息进行合法性测试,并将合法性测试通过的第一信息设置为第二信息,此操作主要是为了对用户选择的第一信息进行初步的核对,因为如果用户选择的第一信息不合法的话,那就意味着之后生成的结构化执行语句是错误的,也就没有了生成的意义。The first information is obtained from the metadata. The metadata is a description of the data resource, and the first information includes the library name, table name, and field name selected by the user. Carry out a legality test on the first information, and set the first information that passes the legality test as the second information. This operation is mainly for the preliminary check of the first information selected by the user, because if the first information selected by the user If it is illegal, it means that the structured execution statement generated later is wrong, and there is no meaning of generation.
对第一信息进行合法性测试,具体包括:Conduct a legality test on the first information, specifically including:
服务器接收用户选择的第一信息,将第一信息和指定数据库中的信息去比对,这里的指定数据库是指存储有元数据的数据库,元数据中的信息都是从指定数据库中获取的,因此,间接的说明第一信息是来源于指定数据库中的。在第一信息存在于指定数据库中时,判定第一信息合法,即说明第一信息是真实存在的,并将合法性测试通过的第一信息设置为第二信息,将第二信息作为待查询信息。The server receives the first information selected by the user, and compares the first information with the information in the specified database. The specified database here refers to the database storing metadata, and the information in the metadata is obtained from the specified database. Therefore, it indirectly indicates that the first information is derived from the specified database. When the first information exists in the specified database, it is determined that the first information is legal, that is, the first information is real, and the first information that passes the legality test is set as the second information, and the second information is used as the query information.
这里,需要进一步说明的是,因为元数据信息并不是真实的数据库,是从指定数据库中取得的,并不会随着指定数据库中的数据去同步更新,可能相对于指定数据库会存在更新不及时的情况,因此,需要把用户选择的第一信息去和指定数据库中的信息去比对。在第一信息不存在于指定数据库中时,判定第一信息不合法,并提示用户重新选择,即说明存在更新不及时的情况,所要分析的数据并不存在于指定数据库中,便需要提示用户重新进行选择。Here, it needs to be further explained that because the metadata information is not a real database, it is obtained from the specified database, and will not be updated synchronously with the data in the specified database, and there may be delays in updating relative to the specified database Therefore, it is necessary to compare the first information selected by the user with the information in the specified database. When the first information does not exist in the designated database, it is judged that the first information is illegal, and the user is prompted to choose again, which means that there is a situation that the update is not timely, and the data to be analyzed does not exist in the designated database, so the user needs to be prompted Make your selection again.
上述通过对第一信息的合法性进行测试,确保用户选择的待查询信息是真实存在的,进而实现后期对于待查询信息的进一步分析和比对。By testing the legitimacy of the first information above, it is ensured that the information to be queried selected by the user is real, and further analysis and comparison of the information to be queried is realized later.
在其中一个实施例中,还需要对结构化执行语句进行格式化处理和语法校对,使得结构化执行语句符合关系型数据库的语法标准。In one of the embodiments, the structured execution statement needs to be formatted and grammatically checked, so that the structured execution statement complies with the syntax standard of the relational database.
其中,在对结构化执行语句进行格式化处理时,包括将结构化执行语句中的空白字符替换为单个空格以及将结构化执行语句统一为大写字母或者小写字母,使得结构化执行语句形成统一;其中,对结构化执行语句进行语法校对,包括对结构化执行语句中的特殊字符以及保留字进行错误纠正,从而,保证结构化执行语句的正确性和可执行性。Among them, when the structured execution statement is formatted, it includes replacing blank characters in the structured execution statement with a single space and unifying the structured execution statement into uppercase or lowercase letters, so that the structured execution statement is unified; Wherein, the syntax proofreading of the structured execution statement includes error correction of special characters and reserved words in the structured execution statement, so as to ensure the correctness and executability of the structured execution statement.
在其中一个实施例中,根据结构化执行语句生成全局唯一ID;并将结构化执行语句和ID存入数据库关系表中之后,还包括如下步骤:In one of the embodiments, a globally unique ID is generated according to the structured execution statement; and after storing the structured execution statement and the ID in the relational table of the database, the following steps are further included:
根据ID创建任务实例,由于每个ID对应一个独立任务,在用户将任务实例触发之后,任务实例会根据传过来的ID创建spark任务,服务器从数据库关系表中提取对应于任务实例的结构化执行语句进行执行,并将获得的执行结果输出到数据库结果表中,且每个任务实例执行完成之后自动消失,同时,多个任务实例可以同步进行。需要说明的是,这里的数据库结果表和数据库关系表类似,都是在一个数据库中,只是属于不同类型的表格而已,用于存储不同类型的数据。Create a task instance according to the ID. Since each ID corresponds to an independent task, after the user triggers the task instance, the task instance will create a spark task according to the passed ID, and the server extracts the structured execution corresponding to the task instance from the database relational table. Statements are executed, and the obtained execution results are output to the database result table, and each task instance disappears automatically after execution, and multiple task instances can be performed simultaneously. It should be noted that the database result table here is similar to the database relationship table, both of which are in the same database, but belong to different types of tables and are used to store different types of data.
在任务实例执行成功时,将ID、执行结果以及成功状态存入数据库结果表中,这里,在任务实例执行成功之后,会有对应的执行结果,将ID、执行结果和成功的状态一一对应保存于数据库结果表中,方便后期工作人员对其进行查看,并且将执行结果回显于操作界面,以便于工作人员看到当前的运行结果;在任务实例执行失败时,将ID、失败状态以及报错日志存入数据库结果表中,因为在任务执行失败的时候是没有执行结果的,那么,便会生成失败日志,连同失败状态和ID一同存入数据库结果表中,以便于后期提示工作人员避免犯同等类型的错误,并且将错误日志回显于操作界面,方便工作人员看到当前的执行状态;当然,服务器对数据库关系表和数据库结果表中的数据也需要保持实时的更新。When the task instance is successfully executed, the ID, execution result, and success status are stored in the database result table. Here, after the task instance is successfully executed, there will be a corresponding execution result, and the ID, execution result, and successful status are in one-to-one correspondence It is saved in the database result table, which is convenient for the staff to view it later, and the execution result is echoed to the operation interface, so that the staff can see the current running result; when the execution of the task instance fails, the ID, failure status and The error log is stored in the database result table, because there is no execution result when the task execution fails, then the failure log will be generated and stored in the database result table together with the failure status and ID, so as to remind the staff later to avoid Make the same type of mistake, and echo the error log to the operation interface, so that the staff can see the current execution status; of course, the server also needs to keep the data in the database relationship table and database result table updated in real time.
进一步的,用户操作界面向服务端发起数据展示请求,服务器处理请求从数据库结果表中获取需要展示的数据并返回给用户操作界面,用户在用户操作界面根据终端的图表可视化库,调取图表可视化库中指定好的图表样式进行数据组装,实现对数据的可视化展示。Furthermore, the user operation interface initiates a data display request to the server, and the server processes the request to obtain the data to be displayed from the database result table and returns it to the user operation interface. The user calls the graph visualization library on the user operation interface according to the terminal’s graph visualization library. The chart style specified in the library is used to assemble the data to realize the visual display of the data.
上述操作,支持对多个结构化执行语句的实时批量执行,并提供对执行语句、执行状态和执行结果的存储与管理,能够提高不同离线表数据形态的对比和分析的处理效率,降低数据开发中的问题和异常,提高数据开发质量;同时,对数据库结果表中的数据的可视化展示,解决了数据库结果表中对于数据的展示不直观、不方便统一观看等问题。The above operations support real-time batch execution of multiple structured execution statements, and provide storage and management of execution statements, execution status, and execution results, which can improve the processing efficiency of comparison and analysis of different offline table data forms, and reduce data development. The problems and exceptions in the database can improve the quality of data development; at the same time, the visual display of the data in the database result table solves the problems of unintuitive display of data in the database result table and inconvenient unified viewing.
应该理解的是,虽然图2流程图中的各个步骤按照箭头的指示依次显示,但是这些步骤并不是必然按照箭头指示的顺序依次执行。除非本文中有明确的说明,这些步骤的执行并没有严格的顺序限制,这些步骤可以以其它的顺序执行。而且,图2中的至少一部分步骤可以包括多个子步骤或者多个阶段,这些子步骤或者阶段并不必然是在同一时刻执行完成,而是可以在不同的时刻执行,这些子步骤或者阶段的执行顺序也不必然是依次进行,而是可以与其它步骤或者其它步骤的子步骤或者阶段的至少一部分轮流或者交替地执行。It should be understood that although the various steps in the flow chart of FIG. 2 are displayed sequentially according to the arrows, these steps are not necessarily executed sequentially in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least some of the steps in FIG. 2 may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but may be executed at different times. The execution of these sub-steps or stages The order is not necessarily performed sequentially, but may be performed alternately or alternately with at least a part of other steps or sub-steps or stages of other steps.
在一个实施例中,如图3所示,提供了一种生成结构化查询语句的装置,包括:获取模块302、预处理模块304和生成模块306,其中:In one embodiment, as shown in FIG. 3 , an apparatus for generating a structured query statement is provided, including: an acquisition module 302, a preprocessing module 304, and a generation module 306, wherein:
获取模块302,用于获取待查询信息和预置的结构化查询语句模板。The acquiring module 302 is configured to acquire the information to be queried and a preset structured query statement template.
预处理模块304,用于将预置的结构化查询语句模板中的动态信息替换为待查询信息,生成结构化执行语句。The preprocessing module 304 is configured to replace the dynamic information in the preset structured query statement template with the information to be queried, and generate a structured execution statement.
生成模块306,用于根据结构化执行语句生成全局唯一ID;并将结构化执行语句和ID存入数据库关系表中。The generating module 306 is configured to generate a globally unique ID according to the structured execution statement; and store the structured execution statement and the ID in a relational table of the database.
在一个实施例中,获取模块302,具体还用于:In one embodiment, the acquisition module 302 is also specifically configured to:
从元数据中获取第一信息;对第一信息进行合法性测试,并将合法性测试通过的第一信息设置为第二信息;将第二信息作为待查询信息。The first information is obtained from the metadata; the legality test is performed on the first information, and the first information that passes the legality test is set as the second information; and the second information is used as the information to be queried.
在其中一个实施例中,上述的结构化查询语句的生成装置还包括合法性判断模块(图中未示出),该合法性判断模块用于接收用户选择的第一信息;将第一信息和指定数据库中的信息进行比对,其中,元数据是从指定数据库中获得的;在第一信息存在于指定数据库中时,判定第一信息合法;在第一信息不存在于指定数据库中时,判定第一信息不合法,并提示用户重新选择。In one of the embodiments, the above-mentioned device for generating structured query sentences further includes a legality judgment module (not shown in the figure), which is used to receive the first information selected by the user; combine the first information and The information in the designated database is compared, wherein the metadata is obtained from the designated database; when the first information exists in the designated database, it is determined that the first information is legal; when the first information does not exist in the designated database, It is determined that the first information is invalid, and the user is prompted to make a new selection.
在一个实施例中,预处理模块304,还用于:In one embodiment, the preprocessing module 304 is also used to:
对结构化执行语句进行格式化处理和语法校对,对结构化执行语句进行格式化处理,包括:将结构化执行语句中的空白字符替换为单个空格以及将结构化执行语句统一为大写字母或者小写字母;对结构化执行语句进行语法校对,包括:对结构化执行语句中的特殊字符以及保留字进行错误纠正。Formatting and grammar proofreading of structured execution statements, and formatting of structured execution statements, including: replacing blank characters in structured execution statements with single spaces and unifying structured execution statements into uppercase letters or lowercase Letters; grammar proofreading for structured execution statements, including: error correction for special characters and reserved words in structured execution statements.
在一个实施例中,生成模块306,还用于:In one embodiment, the generation module 306 is also used to:
根据ID创建任务实例;从数据库关系表中提取对应于任务实例的结构化执行语句进行执行,并将获得的执行结果输出到数据库结果表中,且任务实例执行完成之后自动消失。Create a task instance according to the ID; extract the structured execution statement corresponding to the task instance from the database relational table for execution, and output the obtained execution result to the database result table, and the task instance will disappear automatically after the execution is completed.
在任务实例执行成功时,将ID、执行结果以及成功状态存入数据库结果表中,并回显于操作界面;在任务实例执行失败时,将ID、失败状态以及报错日志存入数据库结果表中,并回显于操作界面。When the task instance executes successfully, store the ID, execution result and success status in the database result table, and display it on the operation interface; when the task instance fails to execute, store the ID, failure status and error log in the database result table , and echo it on the operation interface.
关于一种结构化查询语句的生成装置的具体限定可以参见上文中对于一种结构化查询语句的生成方法的限定,在此不再赘述。上述一种生成结构化查询语句的装置中的各个模块可全部或部分通过软件、硬件及其组合来实现。上述各模块可以硬件形式内嵌于或独立于计算机设备中的处理器中,也可以以软件形式存储于计算机设备中的存储器中,以便于处理器调用执行以上各个模块对应的操作。For specific limitations on a device for generating a structured query statement, refer to the above-mentioned limitation on a method for generating a structured query statement, and details are not repeated here. Each module in the above-mentioned device for generating structured query statements can be fully or partially realized by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, and can also be stored in the memory of the computer device in the form of software, so that the processor can invoke and execute the corresponding operations of the above-mentioned modules.
在一个实施例中,提供了一种计算机设备,该计算机设备可以是服务器,其内部结构图可以如图4所示。该计算机设备包括通过系统总线连接的处理器、存储器、网络接口和数据库。其中,该计算机设备的处理器用于提供计算和控制能力。该计算机设备的存储器包括非易失性存储介质、内存储器。该非易失性存储介质存储有操作系统、计算机程序和数据库。该内存储器为非易失性存储介质中的操作系统和计算机程序的运行提供环境。该计算机设备的数据库用于存储ID和结构化执行语句的关系以及执行结果的数据。该计算机设备的网络接口用于与外部的终端通过网络连接通信。该计算机程序被处理器执行时以实现一种结构化查询语句的生成方法。In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure may be as shown in FIG. 4 . The computer device includes a processor, memory, network interface and database connected by a system bus. Wherein, the processor of the computer device is used to provide calculation and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, computer programs and databases. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The database of the computer device is used to store the relationship between the ID and the structured execution statement and the data of the execution result. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a method for generating structured query statements is realized.
本领域技术人员可以理解,图4中示出的结构,仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的计算机设备的限定,具体的计算机设备可以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。Those skilled in the art can understand that the structure shown in Figure 4 is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation to the computer equipment on which the solution of the application is applied. The specific computer equipment can be More or fewer components than shown in the figures may be included, or some components may be combined, or have a different arrangement of components.
在一个实施例中,提供了一种计算机设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,处理器执行计算机程序时实现以下步骤:In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored on the memory and operable on the processor. When the processor executes the computer program, the following steps are implemented:
获取待查询信息和预置的结构化查询语句模板;Obtain the information to be queried and the preset structured query statement template;
将预置的结构化查询语句模板中的动态信息替换为待查询信息,生成结构化执行语句;Replace the dynamic information in the preset structured query statement template with the information to be queried to generate a structured execution statement;
根据结构化执行语句生成全局唯一ID;并将结构化执行语句和ID存入数据库关系表中。Generate a globally unique ID according to the structured execution statement; and store the structured execution statement and the ID in the database relational table.
在一个实施例中,在处理器执行计算机程序实现上述的获取当前的待查询信息的步骤时,具体实现以下步骤:In one embodiment, when the processor executes the computer program to implement the above-mentioned steps of obtaining the current information to be queried, the following steps are specifically implemented:
从元数据中获取第一信息;对第一信息进行合法性测试,并将合法性测试通过的第一信息设置为第二信息;将第二信息作为待查询信息。The first information is obtained from the metadata; the legality test is performed on the first information, and the first information that passes the legality test is set as the second information; and the second information is used as the information to be queried.
在对第一信息进行合法性测试时,包括:When testing the legality of the first information, including:
服务器接收用户选择的第一信息;将第一信息和指定数据库中的信息进行比对,其中,元数据是从指定数据库中获得的;在第一信息存在于指定数据库中时,判定第一信息合法;在第一信息不存在于指定数据库中时,判定第一信息不合法,并提示用户重新选择。The server receives the first information selected by the user; compares the first information with the information in the specified database, wherein the metadata is obtained from the specified database; when the first information exists in the specified database, determines the first information Legal; when the first information does not exist in the specified database, it is judged that the first information is not legal, and the user is prompted to choose again.
在一个实施例中,处理器执行计算机程序时还实现以下步骤:In one embodiment, the following steps are also implemented when the processor executes the computer program:
对结构化执行语句进行格式化处理和语法校对;其中,对结构化执行语句进行格式化处理,包括:将结构化执行语句中的空白字符替换为单个空格以及将结构化执行语句统一为大写字母或者小写字母;Perform formatting processing and grammar proofreading on the structured execution statement; among them, perform formatting processing on the structured execution statement, including: replacing blank characters in the structured execution statement with a single space and unifying the structured execution statement into uppercase letters or lowercase letters;
对结构化执行语句进行语法校对,包括:对结构化执行语句中的特殊字符以及保留字进行错误纠正。Grammatical proofreading for structured execution statements, including: error correction for special characters and reserved words in structured execution statements.
在一个实施例中,在处理器执行计算机程序实现上述的根据结构化执行语句生成全局唯一ID;并将结构化执行语句和ID存入数据库关系表中的步骤后,还包括:In one embodiment, after the processor executes the computer program to realize the above-mentioned steps of generating a globally unique ID according to the structured execution statement; and storing the structured execution statement and the ID in the database relational table, it also includes:
根据ID创建任务实例;从数据库关系表中提取对应于任务实例的结构化执行语句进行执行,并将获得的执行结果输出到数据库结果表中,且任务实例执行完成之后自动消失。Create a task instance according to the ID; extract the structured execution statement corresponding to the task instance from the database relational table for execution, and output the obtained execution result to the database result table, and the task instance will disappear automatically after the execution is completed.
在处理器执行计算机程序时具体还包括:Specifically, when the processor executes the computer program, it also includes:
在任务实例执行成功时,将ID、执行结果以及成功状态存入数据库结果表中,并回显于操作界面;在任务实例执行失败时,将ID、失败状态以及报错日志存入数据库结果表中,并回显于操作界面。When the task instance executes successfully, store the ID, execution result and success status in the database result table, and display it on the operation interface; when the task instance fails to execute, store the ID, failure status and error log in the database result table , and echo it on the operation interface.
在一个实施例中,提供了一种计算机可读存储介质,其上存储有计算机程序,计算机程序被处理器执行时实现以下步骤:In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
获取待查询信息和预置的结构化查询语句模板;Obtain the information to be queried and the preset structured query statement template;
将预置的结构化查询语句模板中的动态信息替换为待查询信息,生成结构化执行语句;Replace the dynamic information in the preset structured query statement template with the information to be queried to generate a structured execution statement;
根据结构化执行语句生成全局唯一ID;并将结构化执行语句和ID存入数据库关系表中。Generate a globally unique ID according to the structured execution statement; and store the structured execution statement and the ID in the database relational table.
在一个实施例中,在计算机程序被处理器执行上述的获取当前的待查询信息的步骤时,具体实现以下步骤:In one embodiment, when the computer program is executed by the processor for the above-mentioned steps of obtaining the current information to be queried, the following steps are specifically implemented:
从元数据中获取第一信息; 对第一信息进行合法性测试,并将合法性测试通过的第一信息设置为第二信息;将第二信息作为待查询信息。Obtain the first information from the metadata; perform a legality test on the first information, and set the first information that passes the legality test as the second information; and use the second information as the information to be queried.
在对第一信息进行合法性测试时,包括:When testing the legality of the first information, including:
服务器接收用户选择的第一信息;将第一信息和指定数据库中的信息进行比对,其中,元数据是从指定数据库中获得的;在第一信息存在于指定数据库中时,判定第一信息合法;在第一信息不存在于指定数据库中时,判定第一信息不合法,并提示用户重新选择。The server receives the first information selected by the user; compares the first information with the information in the specified database, wherein the metadata is obtained from the specified database; when the first information exists in the specified database, determines the first information Legal; when the first information does not exist in the specified database, it is judged that the first information is not legal, and the user is prompted to choose again.
在一个实施例中,在计算机程序被处理器执行时还实现以下步骤:In one embodiment, the following steps are also implemented when the computer program is executed by the processor:
对结构化执行语句进行格式化处理和语法校对;其中,对结构化执行语句进行格式化处理,包括:将结构化执行语句中的空白字符替换为单个空格以及将结构化执行语句统一为大写字母或者小写字母;Perform formatting processing and grammar proofreading on the structured execution statement; among them, perform formatting processing on the structured execution statement, including: replacing blank characters in the structured execution statement with a single space and unifying the structured execution statement into uppercase letters or lowercase letters;
对结构化执行语句进行语法校对,包括:对结构化执行语句中的特殊字符以及保留字进行错误纠正。Grammatical proofreading for structured execution statements, including: error correction for special characters and reserved words in structured execution statements.
在一个实施例中,在计算机程序被处理器执行上述的根据结构化执行语句生成全局唯一ID;并将结构化执行语句和ID存入数据库关系表中的步骤后,还包括:In one embodiment, after the computer program is executed by the processor to generate the globally unique ID according to the structured execution statement; and store the structured execution statement and the ID in the database relational table, it also includes:
根据ID创建任务实例;从数据库关系表中提取对应于任务实例的结构化执行语句进行执行,并将获得的执行结果输出到数据库结果表中,且任务实例执行完成之后自动消失。Create a task instance according to the ID; extract the structured execution statement corresponding to the task instance from the database relational table for execution, and output the obtained execution result to the database result table, and the task instance will disappear automatically after the execution is completed.
在计算机程序被处理器执行时具体还包括:When the computer program is executed by the processor, it specifically includes:
在任务实例执行成功时,将ID、执行结果以及成功状态存入数据库结果表中,并回显于操作界面;在任务实例执行失败时,将ID、失败状态以及报错日志存入数据库结果表中,并回显于操作界面。When the task instance executes successfully, store the ID, execution result and success status in the database result table, and display it on the operation interface; when the task instance fails to execute, store the ID, failure status and error log in the database result table , and echo it on the operation interface.
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,的计算机程序可存储于一非易失性计算机可读取存储介质中,该计算机程序在执行时,可包括如上述各方法的实施例的流程。其中,本申请所提供的各实施例中所使用的对存储器、存储、数据库或其它介质的任何引用,均可包括非易失性和/或易失性存储器。非易失性存储器可包括只读存储器(ROM)、可编程ROM(PROM)、电可编程ROM(EPROM)、电可擦除可编程ROM(EEPROM)或闪存。易失性存储器可包括随机存取存储器(RAM)或者外部高速缓冲存储器。作为说明而非局限,RAM以多种形式可得,诸如静态RAM(SRAM)、动态RAM(DRAM)、同步DRAM(SDRAM)、双数据率SDRAM(DDRSDRAM)、增强型SDRAM(ESDRAM)、同步链路(Synchlink) DRAM(SLDRAM)、存储器总线(Rambus)直接RAM(RDRAM)、直接存储器总线动态RAM(DRDRAM)、以及存储器总线动态RAM(RDRAM)等。Those of ordinary skill in the art can understand that realizing all or part of the processes in the methods of the above embodiments can be completed by instructing related hardware through computer programs, and the computer programs can be stored in a non-volatile computer-readable storage medium , when the computer program is executed, it may include the procedures of the embodiments of the above-mentioned methods. Wherein, any references to memory, storage, database or other media used in the various embodiments provided in the present application may include non-volatile and/or volatile memory. Nonvolatile memory can include read only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchronous Chain Synchlink DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
以上实施例的各技术特征可以进行任意的组合,为使描述简洁,未对上述实施例中的各个技术特征所有可能的组合都进行描述,然而,只要这些技术特征的组合不存在矛盾,都应当认为是本说明书记载的范围。The technical features of the above embodiments can be combined arbitrarily. To make the description concise, all possible combinations of the technical features in the above embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, they should be It is considered to be within the range described in this specification.
以上实施例仅表达了本申请的几种实施方式,其描述较为具体和详细,但并不能因此而理解为对发明专利范围的限制。应当指出的是,对于本领域的普通技术人员来说,在不脱离本申请构思的前提下,还可以做出若干变形和改进,这些都属于本申请的保护范围。因此,本申请专利的保护范围应以所附权利要求为准。The above examples only express several implementation modes of the present application, and the description thereof is relatively specific and detailed, but should not be construed as limiting the scope of the patent for the invention. It should be noted that those skilled in the art can make several modifications and improvements without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the scope of protection of the patent application should be based on the appended claims.

Claims (10)

  1. 一种结构化查询语句的生成方法,其特征在于,所述方法包括:A method for generating a structured query statement, characterized in that the method comprises:
    获取待查询信息和预置的结构化查询语句模板;Obtain the information to be queried and the preset structured query statement template;
    将所述预置的结构化查询语句模板中的动态信息替换为待查询信息,生成结构化执行语句;replacing the dynamic information in the preset structured query statement template with the information to be queried to generate a structured execution statement;
    根据所述结构化执行语句生成全局唯一ID;并将所述结构化执行语句和所述ID存入数据库关系表中。A globally unique ID is generated according to the structured execution statement; and the structured execution statement and the ID are stored in a database relational table.
  2. 根据权利要求1所述的方法,其特征在于,所述获取待查询信息包括:The method according to claim 1, wherein said obtaining the information to be queried comprises:
    从元数据中获取第一信息; obtain the first information from the metadata;
    对所述第一信息进行合法性测试,并将合法性测试通过的第一信息设置为第二信息;performing a legality test on the first information, and setting the first information that passes the legality test as the second information;
    将所述第二信息作为待查询信息。The second information is used as the information to be queried.
  3. 根据权利要求2所述的方法,其特征在于,所述方法还包括:The method according to claim 2, further comprising:
    接收用户选择的第一信息;Receive the first information selected by the user;
    将所述第一信息和指定数据库中的信息进行比对,其中,所述元数据是从指定数据库中获得的;comparing the first information with information in a specified database, wherein the metadata is obtained from the specified database;
    在所述第一信息存在于所述指定数据库中时,判定所述第一信息合法;determining that the first information is legal when the first information exists in the specified database;
    在所述第一信息不存在于所述指定数据库中时,判定所述第一信息不合法,并提示用户重新选择。When the first information does not exist in the specified database, it is determined that the first information is invalid, and the user is prompted to make a new selection.
  4. 根据权利要求1所述的方法,其特征在于,所述根据所述结构化执行语句生成全局唯一ID;并将所述结构化执行语句和所述ID存入数据库关系表中之后,还包括:The method according to claim 1, wherein said generating a globally unique ID according to said structured execution statement; and storing said structured execution statement and said ID in a database relational table, further comprising:
    根据所述ID创建任务实例;Create a task instance according to the ID;
    从所述数据库关系表中提取对应于所述任务实例的结构化执行语句进行执行,并将获得的执行结果输出到数据库结果表中,且所述任务实例执行完成之后自动消失。The structured execution statement corresponding to the task instance is extracted from the database relational table for execution, and the obtained execution result is output to the database result table, and the task instance disappears automatically after execution is completed.
  5. 根据权利要求4所述的方法,其特征在于,所述从所述数据库关系表中提取对应于所述任务实例的结构化执行语句进行执行,并将获得的执行结果输出到数据库结果表中,且所述任务实例执行完成之后自动消失,包括:The method according to claim 4, wherein the structured execution statement corresponding to the task instance is extracted from the database relational table for execution, and the obtained execution result is output to the database result table, And the task instance disappears automatically after execution is completed, including:
    在所述任务实例执行成功时,将所述ID、执行结果以及成功状态存入数据库结果表中,并回显于操作界面;When the task instance is successfully executed, the ID, execution result and success status are stored in the database result table, and are echoed on the operation interface;
    在所述任务实例执行失败时,将所述ID、失败状态以及报错日志存入数据库结果表中,并回显于操作界面。When the execution of the task instance fails, the ID, failure status and error log are stored in the database result table, and are echoed on the operation interface.
  6. 根据权利要求1所述的方法,其特征在于,所述方法还包括:对所述结构化执行语句进行格式化处理和语法校对。The method according to claim 1, further comprising: performing formatting processing and grammar checking on the structured execution statement.
  7. 根据权利要求6所述的方法,其特征在于,对所述结构化执行语句进行格式化处理,包括:The method according to claim 6, wherein formatting the structured execution statement includes:
    将所述结构化执行语句中的空白字符替换为单个空格以及将所述结构化执行语句统一为大写字母或者小写字母;replacing blank characters in the structured execution statement with a single space and unifying the structured execution statement into uppercase or lowercase letters;
    对所述结构化执行语句进行语法校对,包括:Grammatically proofreading the structured execution statement, including:
    对所述结构化执行语句中的特殊字符以及保留字进行错误纠正。Error correction is performed on special characters and reserved words in the structured execution statement.
  8. 一种结构化查询语句的生成装置,其特征在于,所述装置包括:A device for generating a structured query statement, characterized in that the device includes:
    获取模块,用于获取待查询信息和预置的结构化查询语句模板;The obtaining module is used to obtain the information to be queried and the preset structured query statement template;
    预处理模块,用于将所述预置的结构化查询语句模板中的动态信息替换为待查询信息,生成结构化执行语句;A preprocessing module, configured to replace the dynamic information in the preset structured query statement template with the information to be queried, and generate a structured execution statement;
    生成模块,用于根据所述结构化执行语句生成全局唯一ID;并将所述结构化执行语句和所述ID存入数据库关系表中。A generating module, configured to generate a globally unique ID according to the structured execution statement; and store the structured execution statement and the ID into a database relational table.
  9. 一种计算机设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,其特征在于,所述处理器执行所述计算机程序时实现如权利要求1至7中任一项所述方法的步骤。A computer device, comprising a memory, a processor, and a computer program stored on the memory and operable on the processor, characterized in that, when the processor executes the computer program, any one of claims 1 to 7 is realized. steps of the method described in the item.
  10. 一种计算机可读存储介质,其上存储有计算机程序,其特征在于,所述计算机程序被处理器执行时实现权利要求1至7中任一项所述的方法的步骤。A computer-readable storage medium, on which a computer program is stored, wherein, when the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are realized.
PCT/CN2021/131748 2021-09-27 2021-11-19 Structured query statement generation method and apparatus, and computer device WO2023045054A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111136154.X 2021-09-27
CN202111136154.XA CN113918594A (en) 2021-09-27 2021-09-27 Method and device for generating structured query statement and computer equipment

Publications (1)

Publication Number Publication Date
WO2023045054A1 true WO2023045054A1 (en) 2023-03-30

Family

ID=79236335

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/131748 WO2023045054A1 (en) 2021-09-27 2021-11-19 Structured query statement generation method and apparatus, and computer device

Country Status (2)

Country Link
CN (1) CN113918594A (en)
WO (1) WO2023045054A1 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115470229B (en) * 2022-08-30 2023-04-14 昆仑数智科技有限责任公司 Data table processing method and device, electronic equipment and storage medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108572963A (en) * 2017-03-09 2018-09-25 北京京东尚科信息技术有限公司 Information acquisition method and device
CN110019350A (en) * 2017-07-28 2019-07-16 北京京东尚科信息技术有限公司 Data query method and apparatus based on configuration information
US20190303409A1 (en) * 2017-01-31 2019-10-03 Fujitsu Limited Data search method, data search apparatus, and non-transitory computer-readable storage medium storing program for data search
CN111143399A (en) * 2019-12-19 2020-05-12 微民保险代理有限公司 Data processing method, data processing device, storage medium and computer equipment
CN111414377A (en) * 2020-03-05 2020-07-14 微民保险代理有限公司 Method and device for processing structured query statement and storage medium
CN112650766A (en) * 2019-10-10 2021-04-13 腾讯科技(深圳)有限公司 Database data operation method, system and server

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20190303409A1 (en) * 2017-01-31 2019-10-03 Fujitsu Limited Data search method, data search apparatus, and non-transitory computer-readable storage medium storing program for data search
CN108572963A (en) * 2017-03-09 2018-09-25 北京京东尚科信息技术有限公司 Information acquisition method and device
CN110019350A (en) * 2017-07-28 2019-07-16 北京京东尚科信息技术有限公司 Data query method and apparatus based on configuration information
CN112650766A (en) * 2019-10-10 2021-04-13 腾讯科技(深圳)有限公司 Database data operation method, system and server
CN111143399A (en) * 2019-12-19 2020-05-12 微民保险代理有限公司 Data processing method, data processing device, storage medium and computer equipment
CN111414377A (en) * 2020-03-05 2020-07-14 微民保险代理有限公司 Method and device for processing structured query statement and storage medium

Also Published As

Publication number Publication date
CN113918594A (en) 2022-01-11

Similar Documents

Publication Publication Date Title
CN110297813B (en) Data migration method and device, computer equipment and storage medium
WO2019232828A1 (en) Script deployment method and apparatus, and computer device and storage medium
WO2019232832A1 (en) Data monitoring method and device, computer device, and storage medium
CN110209650B (en) Data normalization and migration method and device, computer equipment and storage medium
US8782604B2 (en) Sandbox support for metadata in running applications
WO2021169272A1 (en) Database table changing method and apparatus, computer device, and storage medium
US20160299745A1 (en) Development method for web development system, and web development system
US8527460B2 (en) Method for carrying out database version control
US20130110879A1 (en) Declarative support for reference data in relational databases
US20180157584A1 (en) Implicit coordination of deployment and regression testing across data centers and system clusters
CN106991104B (en) Database script deployment device and database script deployment method
CN109614315B (en) Automatic generation method and system of data synchronization test case
CN111061475A (en) Software code generation method and device, computer equipment and storage medium
EP2800013A1 (en) Integration database framework
WO2020186808A1 (en) Page permission testing method and apparatus, computer device and storage medium
CN114780641B (en) Multi-library multi-table synchronization method, device, computer equipment and storage medium
US20220365948A1 (en) Systems and methods for facilitating data transformation
WO2023045054A1 (en) Structured query statement generation method and apparatus, and computer device
WO2023202394A1 (en) Partition table creation method and apparatus, data writing method and apparatus for partition table, and data reading method and apparatus for partition table
EP2904520B1 (en) Reference data segmentation from single to multiple tables
CN106990974B (en) APP updating method and device and electronic equipment
CA3191210A1 (en) Data syncronization method and device, computer equipment and storage medium
US20190220531A1 (en) Consistency check for foreign key definition
WO2018201859A1 (en) Method and device for additionally recording data, server and storage medium
CN113282476A (en) Interface performance testing method and device and electronic equipment

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21958167

Country of ref document: EP

Kind code of ref document: A1