Data query method and device, computer device, and storage medium
By parsing and filtering preset keywords in the query statement within the query framework, the problem of not being able to return accurate query results in existing technologies is solved, achieving accurate data return and efficient resource utilization to meet user needs.
Patent Information
- Application Number
- CN202110729386.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-29
- Publication Date
- 2025-12-09
- Estimated Expiration
- 2041-06-29
AI Technical Summary
Existing technologies cannot return accurate query results that meet business needs based on user requirements, resulting in redundant data returns and wasted resources.
By predefining keywords in the query framework, the system parses the preset keywords in the user's input query statement, maps them to filtering instructions, and calls the filtering instructions in the order of logical operators to filter the query results, thereby obtaining the query results required by the user.
It enables the return of accurate query results based on user needs, reduces redundant data, and improves the convenience of data query and the efficiency of resource utilization.
Smart Images

Figure CN115544347B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of big data, and particularly relates to a data query method and device, a computer device and a storage medium. BACKGROUND
[0002] The most commonly used technology of the existing Internet technology is data query of a database. Technical updates in data query focus on object query statement support and query performance functions, but the returned data results are rarely optimized and improved. The data query result presentation mode is relatively fixed and does not meet the use requirements of most users. The data amount included in the query result is comprehensive and complex. However, for users with different business requirements, the data focus that needs to be paid attention to is different. However, the existing technology cannot return accurate query results that meet the business requirements according to the use requirements of users. Only the query results can be returned in a fixed format, which will lead to the return of a large amount of redundant data. Users need to filter the required data from the redundant data again, which is not conducive to the use of users and leads to the waste of network resources and memory resources. SUMMARY
[0003] The main purpose of the present application is to provide a data query method, which aims to solve the technical problem that accurate query results that meet business requirements cannot be returned according to the use requirements of users.
[0004] The present application provides a data query method, which comprises the following steps:
[0005] obtaining a query statement input by a user;
[0006] performing data query on a specified database according to the query statement to obtain a query result;
[0007] determining whether the query statement carries a preset keyword;
[0008] if the query statement carries the preset keyword, calling a parser to parse the preset keyword to obtain a filtering instruction corresponding to the preset keyword;
[0009] filtering the query result through the filtering instruction to obtain a filtered query result.
[0010] Preferably, the step of filtering the query result through the filtering instruction to obtain a filtered query result comprises the following steps:
[0011] determining whether the query statement includes filtering instructions corresponding to a plurality of preset keywords one by one;
[0012] if the query statement includes filtering instructions corresponding to a plurality of preset keywords one by one, identifying a logical operator between the filtering instructions corresponding to the plurality of preset keywords one by one;
[0013] sequencing the calling sequence of the filtering instructions corresponding to the plurality of preset keywords according to the logical operators, to form an instruction sequence;
[0014] sequentially calling the filtering instructions corresponding to the plurality of preset keywords according to the instruction sequence, to filter the query result, and obtain a filtered query result.
[0015] Preferably, the step of sequentially calling the filtering instructions corresponding to the plurality of preset keywords according to the instruction sequence, to filter the query result, and obtain a filtered query result, comprises:
[0016] determining whether the query statement includes a first instruction, wherein the first instruction is included in the filtering instructions corresponding to the plurality of preset keywords, the first instruction is an instruction for setting data corresponding to a first specified field in the query result to be empty, and the first specified field is any field in the query result;
[0017] if the query statement includes the first instruction, setting the data corresponding to the first specified field in the query result to be empty according to the first instruction;
[0018] combining the remaining fields in the query result except the first specified field into a first query result filtered by the first instruction according to the sorting of all fields in the query result, and the first query result is included in the filtered query result.
[0019] Preferably, the step of sequentially calling the filtering instructions corresponding to the plurality of preset keywords according to the instruction sequence, to filter the query result, and obtain a filtered query result, comprises:
[0020] determining whether the query statement includes a second instruction, wherein the second instruction is included in the filtering instructions corresponding to the plurality of preset keywords, and the second instruction is an instruction for returning only data corresponding to a second specified field in the query result;
[0021] if the query statement includes the second instruction, determining the data corresponding to the second specified field in the query result according to the second instruction;
[0022] combining the data corresponding to the second specified field into a second query result filtered by the second instruction, and the second query result is included in the filtered query result.
[0023] Preferably, the step of sequentially calling the filtering instructions corresponding to the plurality of preset keywords according to the instruction sequence, to filter the query result, and obtain a filtered query result, comprises:
[0024] determining whether the query statement comprises a third instruction, wherein the third instruction is included in the filter instruction corresponding to each of the preset keywords, and the third instruction is an instruction for converting data in the query result into an array;
[0025] if the query statement comprises the third instruction symbol, converting data corresponding to each field in the query result into an array respectively according to the third instruction;
[0026] combining the arrays corresponding to each field into an array combination according to the arrangement order of each field in the query result;
[0027] taking the array combination as a third query result filtered by the third instruction, and the third query result is included in the filtered query result.
[0028] Preferably, before the step of obtaining the query statement input by the user, the method comprises:
[0029] obtaining a script file deployed by a query framework function, wherein the script file comprises a parsing preset keyword parser and a mapping relationship between each of the preset keywords and a filter function;
[0030] deploying the preset keyword parser on the query framework by running the script file.
[0031] Preferably, after the step of filtering the query result by the filter instruction to obtain a filtered query result, the method comprises:
[0032] obtaining a historical use record of the user;
[0033] determining whether a specified storage path exists in the historical use record;
[0034] if the specified storage path exists, determining whether a communication state of the specified storage path meets a data transmission requirement;
[0035] if the communication state of the specified storage path meets the data transmission requirement, returning the filtered query result to a user client according to the specified storage path.
[0036] The application further provides a data query device, comprising:
[0037] a first obtaining module configured to obtain a query statement input by a user;
[0038] a query module configured to perform data query from a specified database according to the query statement to obtain a query result;
[0039] The first judging module is configured to judge whether the query statement carries a preset keyword.
[0040] The calling module is configured to call a parser to parse the preset keyword to obtain a filter instruction corresponding to the preset keyword if the query statement carries the preset keyword.
[0041] The filtering module is configured to filter the query result through the filter instruction to obtain a filtered query result.
[0042] The application further provides a computer device comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the method when executing the computer program.
[0043] The application further provides a computer readable storage medium, which stores a computer program, and the computer program implements the steps of the method when executed by a processor.
[0044] The application defines a keyword in advance in the query framework of a platform, and realizes different use requirements of a user by customizing the keyword in the platform. Then, the data query system analyzes the filter function corresponding to the keyword and maps the filter function to a filter instruction corresponding to the keyword. When the user initiates a query, it is judged whether the query statement includes a preset keyword. If the query statement includes the preset keyword, the query result is filtered according to the filter instruction corresponding to the keyword, and the query result meeting the use requirement of the user is returned to the user terminal, so that the precise query result meeting the business requirement is returned according to the use requirement of the user, and there is no need to further screen, process or sort, thereby improving the convenience of data query. BRIEF DESCRIPTION OF DRAWINGS
[0045] Figure 1 A data query method flowchart of an embodiment of the application;
[0046] Figure 2 A structure diagram of a data query device of an embodiment of the application;
[0047] Figure 3 An internal structure diagram of a computer device of an embodiment of the application. DETAILED DESCRIPTION
[0048] In order to make the objects, technical solutions and advantages of the application clearer, the application will be further described in detail below with reference to the drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the application and should not be used to limit the application.
[0049] Reference Figure 1 A data query method of an embodiment of the application comprises:
[0050] S1: obtaining a query statement input by a user;
[0051] S2: querying data from a specified database according to the query statement to obtain a query result;
[0052] S3: judging whether the query statement carries a preset keyword;
[0053] S4: if the query statement carries the preset keyword, calling a parser to parse the preset keyword to obtain a filtering instruction corresponding to the preset keyword;
[0054] S5: filtering the query result through the filtering instruction to obtain a filtered query result.
[0055] In the embodiment of the application, the query statement input by the user is not only used to obtain query data from the database, but also used to filter the query result through the flag carried in the query statement, so that the data fed back to the user terminal can directly meet the user demand. Through keyword recognition, it is judged whether the query statement input by the user carries a preset keyword. If the preset keyword is carried, the preset keyword is sent to the parser. The parser parses the filtering instruction corresponding to the keyword according to the mapping relationship between the preset keyword and the filtering instruction. Then, the query data is filtered according to the filtering instruction to remove redundant data, so as to obtain the query result required by the user and return it. The above-mentioned preset keyword includes but is not limited to "SET NULL", "SET ONLY", "SET ReturnAsArray" and the like. "SET NULL" corresponds to the filtering instruction "setting the data of the corresponding field to null", "SET ONLY" corresponds to the filtering instruction "returning only the data of the corresponding field", and "SET ReturnAsArray" corresponds to the filtering instruction "setting the data of the corresponding field to an array".
[0056] The application predefines the keyword in the query framework of the platform, realizes different use requirements of the user through the way of customizing and setting the keyword in the platform, then the system parses the filtering function corresponding to the keyword and maps it to the operation instruction corresponding to the keyword, when the user initiates the query instruction, it is judged whether the instruction is the preset keyword, if yes, the query result is filtered according to the filtering function corresponding to the keyword, or the data queried from the database is converted according to the operation instruction, so as to obtain the query result required by the user and return it to the user terminal, so as to realize the accurate query result meeting the business requirement according to the use requirement of the user, without further screening or sorting, and improve the convenience of data query.
[0057] Further, the step S5 of filtering the query result through the filtering instruction to obtain the filtered query result comprises:
[0058] S51: determining whether the query statement includes a plurality of filter instructions corresponding to the plurality of preset keywords one by one;
[0059] S52: if the query statement includes a plurality of filter instructions corresponding to the plurality of preset keywords one by one, identifying a logical operator between the plurality of filter instructions corresponding to the plurality of preset keywords one by one;
[0060] S53: sorting the calling sequence of the plurality of filter instructions corresponding to the plurality of preset keywords according to the logical operator to form an instruction sequence;
[0061] S54: sequentially calling the filter instructions corresponding to the plurality of preset keywords according to the instruction sequence to filter the query result to obtain a filtered query result.
[0062] In the embodiments of the present application, the plurality of preset keywords can appear in the query statement of the user at the same time, and the data corresponding to different fields of the query result is processed respectively; or one of the plurality of preset keywords can be used alone to perform a specified filtering on the query result. The filtering process corresponding to the plurality of preset keywords has the same principle whether in the scenario of using the plurality of preset keywords or using a single preset keyword. The difference is that in the scenario of using the plurality of preset keywords, the filtering results of the single preset keyword are sequentially spliced according to the logical operator between the plurality of preset keywords to form the final query result. The query statement of the user is formed by combining the information keyword and the query condition keyword. The query condition keyword is composed of the preset keyword. When the plurality of preset keywords appear in the query statement of the user at the same time, the plurality of preset keywords can be connected through the logical operator to distinguish the running order of the filter instructions corresponding to the plurality of preset keywords. The logical operator includes but is not limited to "or" and "and". "or" means parallel execution, and "and" means sequential execution. When the user selects the preset keyword, the selection can be limited in a selectable or non-selectable manner to avoid logical errors. For example, if the first field of the query result is set to the preset keyword "SET NULL", the preset keyword "SET ReturnAsArray" cannot be set to the first field. For another example, if the first field of the query result is set to the preset keyword "SET ONLY", the preset keyword "SET ReturnAsArray" can be set to the first field. The logical execution of the filter instructions is realized through the logical operator, which can better meet the use requirements of the user.
[0063] Further, the step S54 of filtering the query result according to the filter instruction corresponding to each of the preset keywords in sequence to obtain a filtered query result comprises:
[0064] S511: judging whether the query statement comprises a first instruction, wherein the first instruction is contained in the filter instruction corresponding to each of the preset keywords, the first instruction is an instruction of setting data corresponding to a first designated field in the query result as null, and the first designated field is any field in the query result;
[0065] S512: if the query statement comprises the first instruction, setting the data corresponding to the first designated field in the query result as null according to the first instruction;
[0066] S513: combining the sorting remaining fields in the query result except the first designated field into a first query result filtered by the first instruction according to the sorting of all the fields in the query result, and the first query result is contained in the filtered query result.
[0067] In the embodiments of the present application, the filtering instructions corresponding to the preset keywords are different. When a preset keyword is connected with a specific field in the query result, it indicates that the filtering instruction corresponding to the preset keyword is executed on the specific field. Each preset keyword can be used on a specific field alone or on two or more fields. The embodiments of the present application take the keyword "SET NULL" as an example for detailed description. "SET NULL" corresponds to the filtering instruction "setting the data of the corresponding field to null". "SET NULL" can be connected with one field in the query result or represented in the form of an array, for example, "the first specified field: SET NULL" indicates that the first specified field is connected with SET NULL, that is, the filtering operation of setting the data to null is executed on the first specified field. For example, the marketData data is composed of marketPrice=1.2, companyName=PAS, and exchangeName=SH. If Select*from marketData set null exchangeName, the filtered query result is: marketPrice=1.2, companyName=PAS, and exchangeName=null. "SET NULL" can be connected with more than one field in the query result, but it must be ensured that it does not cover all fields of the query result, otherwise it is meaningless. For example, Select*from marketData set null companyName, set null exchangeName, the filtered query result is: marketPrice=1.2, companyName=null, and exchangeName=null.
[0068] Further, the step S54 of filtering the query result according to the filtering instructions corresponding to the preset keywords in sequence according to the instruction sequence to obtain the filtered query result comprises:
[0069] S5101: determining whether the query statement includes a second instruction, wherein the second instruction is included in the filtering instructions corresponding to all the preset keywords, and the second instruction is a symbol of an instruction of returning only the data corresponding to a second specified field in the query result;
[0070] S5102: if the query statement includes the second instruction, determining the data corresponding to the second specified field in the query result according to the second instruction;
[0071] S5103: taking the data corresponding to the second specified field as the second query result filtered by the second instruction, and the second query result is included in the filtered query result.
[0072] The embodiment of the application takes the preset keyword "SET ONLY" as an example for detailed description. "SET ONLY" corresponds to the filtering instruction "return data of corresponding field only", so "SET ONLY" is used for querying one field in the query result only, and cannot be used for querying multiple fields simultaneously. For example, the query statement of a user is "Select * from marketDataset only companyName", and the filtered query data is returned as marketPrice = null, companyName = PAS, and exchangeName = null.
[0073] Further, the step S54 of filtering the query result according to the filtering instructions corresponding to the preset keywords in sequence according to the instruction order comprises:
[0074] S5111: determining whether the query statement includes a third instruction, wherein the third instruction is included in the filtering instructions corresponding to all the preset keywords, and the third instruction is an instruction of converting data in the query result into an array;
[0075] S5112: if the query statement includes the third instruction symbol, converting data corresponding to each field in the query result into an array according to the third instruction;
[0076] S5113: combining the arrays corresponding to each field into an array combination according to the arrangement order of each field in the query result;
[0077] S5114: taking the array combination as a third query result filtered by the third instruction, and the third query result is included in the filtered query result.
[0078] The embodiment of the application takes the preset keyword "SET ReturnAsArray" as an example for detailed description. "SETReturnAsArray" corresponds to the filtering instruction "set data of corresponding field as an array", and is a kind of limitation on the data format of the query result, and can be used together with "SET ONLY" described above, including data limitation on the same field or different fields. "SETReturnAsArray" can also be used together with "SET NULL" described above, including data limitation on different fields, but cannot be used together for the same field, otherwise it is meaningless.
[0079] Further, the step S1 of obtaining the query statement input by the user comprises:
[0080] S11: Obtain a script file deployed by a query framework function, wherein the script file comprises a preset keyword parser and a mapping relationship between each preset keyword and a filtering function;
[0081] S12: Deploy the preset keyword parser on the query framework by running the script file.
[0082] The query framework of the embodiment of the application deploys a parser, such as a SQL parser, through a script, and predefines a one-to-one mapping relationship between a preset keyword and a filtering instruction in the SQL parser. The mapping relationship includes but is not limited to that "SET NULL" corresponds to a filtering instruction "set the data of a corresponding field to null", "SET ONLY" corresponds to a filtering instruction "return only the data of a corresponding field", and "SET ReturnAsArray" corresponds to a filtering instruction "set the data of a corresponding field to an array". For example, if a query statement of a user is "Select*from marketData RETURN AS ARRAY", the returned data after filtering is [marketPrice = 1.2, companyName = PAS, exchangeName = SH].
[0083] Further, after the step S5 of filtering the query result through the filtering instruction to obtain a filtered query result, the method further comprises:
[0084] S501: Obtain a historical use record of a user;
[0085] S502: Determine whether a specified storage path exists in the historical use record;
[0086] S503: If the specified storage path exists, determine whether a communication state of the specified storage path meets a data transmission requirement;
[0087] S504: If the communication state of the specified storage path meets the data transmission requirement, return the filtered query result to a user client according to the specified storage path.
[0088] The application not only filters the query result, but also limits the return mode of the query result to better meet the user's data query requirements. For example, the query framework of the embodiment of the application can obtain the historical record of the data query of the user corresponding account, and analyze and obtain effective data. The above-mentioned effective data includes the storage path commonly used by the user, the setting record of the query condition keyword selected by the user last time, the contact interface for information reminding, etc., to form a personalized query interface and format for the user, facilitate the user to form a personalized operation interface according to the respective use habit, and facilitate the user to directly call the query template formed by the query framework for the current user for rapid query. The above-mentioned query template is formed by obtaining the effective data in the above-mentioned historical record.
[0089] With reference to Figure 2 The data query device of the embodiment of the application comprises:
[0090] The first obtaining module 1 is configured to obtain a query statement input by a user.
[0091] The query module 2 is configured to perform data query from a specified database according to the query statement to obtain a query result.
[0092] The first judging module 3 is configured to judge whether the query statement carries a preset keyword.
[0093] The calling module 4 is configured to call a parser to parse the preset keyword to obtain a filtering instruction corresponding to the preset keyword if the query statement carries the preset keyword.
[0094] The filtering module 5 is configured to filter the query result through the filtering instruction to obtain a filtered query result.
[0095] The related explanations of the embodiment of the application are not described in detail.
[0096] Further, the filtering module 5 comprises:
[0097] The first judging unit is configured to judge whether the query statement includes a plurality of filtering instructions corresponding to the preset keywords one by one.
[0098] The identifying unit is configured to identify the logical operators between the plurality of filtering instructions corresponding to the preset keywords one by one if the query statement includes the plurality of filtering instructions corresponding to the preset keywords one by one.
[0099] The filtering unit is configured to sequentially call the filtering instructions corresponding to the preset keywords in the order of the instructions, and filter the query result to obtain a filtered query result.
[0100] Further, the filtering unit comprises:
[0101] The first judging subunit is configured to determine whether the query statement comprises a first instruction, wherein the first instruction is included in the filtering instructions corresponding to all the preset keywords, the first instruction is an instruction for setting data corresponding to a first designated field in the query result as null, and the first designated field is any field in the query result.
[0102] The setting subunit is configured to, if the query statement comprises the first instruction, set the data corresponding to the first designated field in the query result as null according to the first instruction.
[0103] The combining subunit is configured to combine the sorting remaining fields in the query result except the first designated field into a first query result filtered by the first instruction according to the sorting of all the fields in the query result, and the first query result is included in the filtered query result.
[0104] Further, the filtering unit comprises:
[0105] The second judging subunit is configured to determine whether the query statement comprises a second instruction, wherein the second instruction is included in the filtering instructions corresponding to all the preset keywords, and the second instruction is an instruction for returning only data corresponding to a second designated field in the query result.
[0106] The determining subunit is configured to, if the query statement comprises the second instruction, determine the data corresponding to the second designated field in the query result according to the second instruction.
[0107] The first as subunit is configured to take the data corresponding to the second designated field as a second query result filtered by the second instruction, and the second query result is included in the filtered query result.
[0108] Further, the filtering unit comprises:
[0109] The third judging subunit is configured to determine whether the query statement comprises a third instruction, wherein the third instruction is included in the filtering instructions corresponding to all the preset keywords, and the third instruction is an instruction for converting data in the query result into an array.
[0110] The converting subunit is configured to convert data corresponding to each field in the query result into an array respectively according to the third instruction if the query statement includes the third instruction symbol;
[0111] The composing subunit is configured to compose the array corresponding to each field into an array combination according to the arrangement order of each field in the query result;
[0112] The second subunit is configured to take the array combination as a third query result filtered by the third instruction, and the third query result is included in the filtered query result.
[0113] Further, the data query device comprises:
[0114] The second obtaining module is configured to obtain a script file deployed by a query framework function, wherein the script file includes a preset keyword parser and a mapping relationship between each preset keyword and a filtering function;
[0115] The deployment module is configured to deploy the preset keyword parser on the query framework by running the script file.
[0116] Further, the data query device comprises:
[0117] The second obtaining module is configured to obtain a user's historical use record;
[0118] The second judging module is configured to judge whether a specified storage path exists in the historical use record;
[0119] The third judging module is configured to judge whether a communication state of the specified storage path meets data transmission requirements if the specified storage path exists in the historical use record;
[0120] The returning module is configured to return the filtered query result to a user client according to the specified storage path if the communication state of the specified storage path meets the data transmission requirements.
[0121] Reference Figure 3 In the embodiments of the present application, a computer device, which can be a server, is also provided, and an internal structure of the computer device can be as shown in Figure 3The computer device includes a processor, a memory, a network interface and a database connected by a system bus. The processor of the computer device is configured to provide computing 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, a computer program and a database. The internal memory provides an environment for the operating system and the computer program in the non-volatile storage medium. The database of the computer device is configured to store all data required by the data query process. The network interface of the computer device is configured to communicate with an external terminal through a network connection. The computer program is executed by the processor to implement the data query method.
[0122] The processor executes the data query method, including: obtaining a query statement input by a user; performing data query from a specified database according to the query statement to obtain a query result; determining whether the query statement carries a preset keyword; if the query statement carries the preset keyword, calling a parser to parse the preset keyword to obtain a filtering instruction corresponding to the preset keyword; and filtering the query result through the filtering instruction to obtain a filtered query result.
[0123] The computer device pre-defines a keyword in a platform query framework, and realizes different use requirements of a user by customizing and setting the keyword in the platform. Then, the data query system maps a filtering function corresponding to the keyword to a filtering instruction corresponding to the keyword by parsing the keyword, determines whether the query statement includes the preset keyword when the user initiates the query, filters the query result according to the filtering instruction corresponding to the keyword if the query statement includes the preset keyword, obtains the query result meeting the use requirement of the user, and returns the query result to the user terminal, so as to return the accurate query result meeting the business requirement according to the use requirement of the user, and improve the convenience of data query.
[0124] In one embodiment, the processor filters the query result through the filtering instruction to obtain the filtered query result, including: determining whether the query statement includes filtering instructions corresponding to a plurality of preset keywords one by one; if the query statement includes the filtering instructions corresponding to the plurality of preset keywords one by one, identifying a logical operator between the filtering instructions corresponding to the plurality of preset keywords one by one; sorting a calling order of the filtering instructions corresponding to the plurality of preset keywords one by one according to the logical operator to form an instruction order; and calling the filtering instructions corresponding to the plurality of preset keywords one by one in the instruction order to filter the query result to obtain the filtered query result.
[0125] In one embodiment, the processor sequentially calls the filtering instructions corresponding to each of the preset keywords according to the instruction sequence, filters the query result, and obtains the filtered query result, including: determining whether the query statement includes a first instruction, wherein the first instruction is included in the filtering instructions corresponding to each of the preset keywords, the first instruction is an instruction for setting the data corresponding to a first designated field in the query result to null, and the first designated field is any field in the query result; if the query statement includes the first instruction, setting the data corresponding to the first designated field in the query result to null according to the first instruction; combining the sorting remaining fields in the query result except the first designated field into a first query result filtered by the first instruction according to the sorting of all fields in the query result, and the first query result is included in the filtered query result.
[0126] In one embodiment, the processor sequentially calls the filtering instructions corresponding to each of the preset keywords according to the instruction sequence, filters the query result, and obtains the filtered query result, including: determining whether the query statement includes a second instruction, wherein the second instruction is included in the filtering instructions corresponding to each of the preset keywords, and the second instruction is an instruction for returning only the data corresponding to a second designated field in the query result; if the query statement includes the second instruction, determining the data corresponding to the second designated field in the query result according to the second instruction; taking the data corresponding to the second designated field as a second query result filtered by the second instruction, and the second query result is included in the filtered query result.
[0127] In one embodiment, the processor sequentially calls the filtering instructions corresponding to each of the preset keywords according to the instruction sequence, filters the query result, and obtains the filtered query result, including: determining whether the query statement includes a third instruction, wherein the third instruction is included in the filtering instructions corresponding to each of the preset keywords, and the third instruction is an instruction for converting the data in the query result into an array; if the query statement includes the third instruction, converting the data corresponding to each field in the query result into an array according to the third instruction; combining the arrays corresponding to each field into an array combination according to the arrangement order of each field in the query result; taking the array combination as a third query result filtered by the third instruction, and the third query result is included in the filtered query result.
[0128] In one embodiment, the processor obtains a script file deployed by the query framework function before the step of obtaining the query sentence input by the user, wherein the script file comprises parsing the preset keyword parser and mapping relationship between each preset keyword and filtering function; and the preset keyword parser is deployed on the query framework by running the script file.
[0129] In one embodiment, after the step of filtering the query result by the filtering instruction to obtain the filtered query result, the processor further comprises: obtaining the historical use record of the user; judging whether the specified storage path exists in the historical use record; if the specified storage path exists in the historical use record, judging whether the communication state of the specified storage path meets the data transmission requirement; and if the communication state of the specified storage path meets the data transmission requirement, returning the filtered query result to the user client according to the specified storage path.
[0130] Those skilled in the art can understand that, Figure 3 The structure shown in the figure is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied.
[0131] An embodiment of the present application further provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to realize a data query method, comprising: obtaining a query sentence input by a user; performing data query from a specified database according to the query sentence to obtain a query result; judging whether the query sentence carries a preset keyword; if the query sentence carries the preset keyword, calling a parser to parse the preset keyword to obtain a filtering instruction corresponding to the preset keyword; and filtering the query result by the filtering instruction to obtain a filtered query result.
[0132] The computer readable storage medium defines the keyword in advance in the query framework of the platform, realizes different use requirements of the user by customizing and setting the keyword in the platform, and then the data query system maps the filtering function corresponding to the keyword to the filtering instruction corresponding to the keyword by parsing the keyword, judges whether the query sentence includes the preset keyword when the user initiates the query, filters the query result according to the filtering instruction corresponding to the keyword if the query sentence includes the preset keyword, obtains the query result meeting the business requirement of the user, and returns the query result to the user terminal, so as to realize returning the accurate query result meeting the business requirement according to the use requirement of the user, and improve the convenience of data query.
[0133] In one embodiment, the processor filters the query result according to the filtering instructions to obtain a filtered query result, including: determining whether the query statement includes filtering instructions corresponding to each of the preset keywords; if the query statement includes filtering instructions corresponding to each of the preset keywords, identifying logical operators between the filtering instructions corresponding to each of the preset keywords; sorting the calling sequence of the filtering instructions corresponding to each of the preset keywords according to the logical operators to form an instruction sequence; and calling the filtering instructions corresponding to each of the preset keywords in the instruction sequence to filter the query result and obtain the filtered query result.
[0134] In one embodiment, the processor filters the query result according to the filtering instructions to obtain a filtered query result, including: determining whether the query statement includes filtering instructions corresponding to each of the preset keywords; if the query statement includes filtering instructions corresponding to each of the preset keywords, identifying logical operators between the filtering instructions corresponding to each of the preset keywords; sorting the calling sequence of the filtering instructions corresponding to each of the preset keywords according to the logical operators to form an instruction sequence; and calling the filtering instructions corresponding to each of the preset keywords in the instruction sequence to filter the query result and obtain the filtered query result.
[0135] In one embodiment, the processor filters the query result according to the filtering instructions to obtain a filtered query result, including: determining whether the query statement includes filtering instructions corresponding to each of the preset keywords; if the query statement includes filtering instructions corresponding to each of the preset keywords, identifying logical operators between the filtering instructions corresponding to each of the preset keywords; sorting the calling sequence of the filtering instructions corresponding to each of the preset keywords according to the logical operators to form an instruction sequence; and calling the filtering instructions corresponding to each of the preset keywords in the instruction sequence to filter the query result and obtain the filtered query result.
[0136] In one embodiment, the processor filters the query result according to the filter instruction corresponding to each of the preset keywords in the order of the instruction sequence to obtain a filtered query result, and the step includes: determining whether the query statement includes a third instruction, wherein the third instruction is included in the filter instruction corresponding to each of the preset keywords, and the third instruction is an instruction for converting the data in the query result into an array; if the query statement includes the third instruction symbol, converting the data corresponding to each field in the query result into an array respectively according to the third instruction; combining the arrays corresponding to each field into an array combination according to the arrangement order of each field in the query result; and taking the array combination as a third query result filtered by the third instruction, wherein the third query result is included in the filtered query result.
[0137] In one embodiment, before the processor obtains the query statement input by the user, the processor obtains a script file deployed by a query framework function, wherein the script file includes a parsing of the preset keyword parser and a mapping relationship between each of the preset keywords and a filter function; and the processor deploys the preset keyword parser on the query framework by running the script file.
[0138] In one embodiment, after the processor filters the query result according to the filter instruction to obtain a filtered query result, the processor obtains a historical use record of the user; determines whether a specified storage path exists in the historical use record; if the specified storage path exists, determines whether a communication state of the specified storage path meets a data transmission requirement; and if the communication state of the specified storage path meets the data transmission requirement, returns the filtered query result to a user client according to the specified storage path.
[0139] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program. The above-mentioned computer program can be stored in a non-volatile computer readable storage medium, and when executed, can include the processes of the above-mentioned embodiment methods. Any reference to memory, storage, databases, or other media in this application and in examples provided herein, unless specifically stated otherwise, can include non-volatile and / or volatile memory. Non-volatile memory can include, for example, read only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include, for example, random access memory (RAM), or external cache memory. As an illustration and not a limitation, RAM is available in many forms such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), Synchlink DRAM (SLDRAM), Rambus DRAM (RDRAM), direct Rambus dynamic RAM (DRDRAM), and Rambus dynamic RAM (RDRAM), etc.
[0140] It should be noted that the terms "comprising", "including", or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, device, article, or method that comprises a list of elements does not include only those elements recited, but can also include other elements not expressly listed or inherent to such process, device, article, or method. Without further limitation, an element defined by the phrase "comprising a" does not exclude the presence of additional identical elements in the process, device, article, or method that includes the element.
[0141] The above description is only the preferred embodiment of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation using the content of the specification and drawings, or direct or indirect application in other related technical fields, is also included in the patent protection scope of the present application.
Claims
1. A data query method, characterized by, The application relates to a method for filtering query results, comprising the following steps: acquiring a user input query statement, wherein the query statement is used to acquire query data from a database, and the query statement carries a flag for filtering the query results, and the acquired query results are re-filtered; querying data from a specified database according to the query statement to obtain query results; judging whether the query statement carries a preset keyword; if the query statement carries the preset keyword, calling a parser to parse the preset keyword to obtain a filtering instruction corresponding to the preset keyword; filtering the query results through the filtering instruction to obtain filtered query results; wherein the filtering step comprises the following steps: judging whether the query statement includes filtering instructions corresponding to multiple preset keywords one by one; if the query statement includes filtering instructions corresponding to multiple preset keywords one by one, identifying logical operators between the filtering instructions corresponding to the multiple preset keywords one by one; sorting the calling sequence of the filtering instructions corresponding to the multiple preset keywords according to the logical operators to form an instruction sequence; calling the filtering instructions corresponding to the multiple preset keywords one by one according to the instruction sequence to filter the query results and obtain filtered query results; wherein the filtering step comprises the following steps: judging whether the query statement includes a first instruction, wherein the first instruction is included in the filtering instructions corresponding to all the preset keywords, the first instruction is an instruction for setting the data corresponding to a first specified field in the query results as null, and the first specified field is any field in the query results; if the query statement includes the first instruction, setting the data corresponding to the first specified field in the query results as null according to the first instruction; combining the remaining fields in the query results except the first specified field into a first query result filtered by the first instruction according to the sorting of all the fields in the query results, and the first query result is included in the filtered query results; wherein the filtering instructions corresponding to the multiple preset keywords are different, and when a preset keyword is connected with a specific field in the query results, the filtering instruction corresponding to the preset keyword is executed on the specific field; each preset keyword can be used on a specific field alone or on two or more fields; wherein the filtering step comprises the following steps: judging whether the query statement includes a second instruction, wherein the second instruction is included in the filtering instructions corresponding to all the preset keywords, and the second instruction is an instruction for returning only the data corresponding to a second specified field in the query results; If the query statement includes a second instruction, data corresponding to a second specified field in the query result is determined according to the second instruction; The data corresponding to the second specified field is taken as a second query result filtered by the second instruction, and the second query result is included in the filtered query result; The step of filtering the query result according to the filter instruction corresponding to each preset keyword in the order of the instruction sequence to obtain a filtered query result includes: It is judged whether the query statement includes a third instruction, wherein the third instruction is included in the filter instruction corresponding to each preset keyword, and the third instruction is an instruction for converting data in the query result into an array; If the query statement includes a third instruction symbol, data corresponding to each field in the query result is converted into an array according to the third instruction; An array combination is formed by arranging the arrays corresponding to each field in the query result according to the arrangement order of each field in the query result; The array combination is taken as a third query result filtered by the third instruction, and the third query result is included in the filtered query result.
2. The data query method of claim 1, wherein, Before the step of obtaining the query statement input by the user, the following steps are included: A script file deployed by a query framework function is obtained, wherein the script file includes a parsing of the preset keyword parser and a mapping relationship between each preset keyword and a filter function; The preset keyword parser is deployed on the query framework by running the script file.
3. The data query method of claim 1, wherein, After the step of filtering the query result by the filter instruction to obtain a filtered query result, the following steps are included: A historical use record of the user is obtained; It is judged whether a specified storage path exists in the historical use record; If the specified storage path exists in the historical use record, it is judged whether a communication state of the specified storage path meets data transmission requirements; If the communication state of the specified storage path meets the data transmission requirements, the filtered query result is returned to the user client according to the specified storage path.
4. A data query apparatus, characterized by comprising: It includes: A first obtaining module is configured to obtain a query statement input by a user, wherein the query statement is used to obtain query data from a database, and a flag for filtering a query result is carried in the query statement, and the obtained query result is further filtered; A query module is configured to perform data query on a specified database according to the query statement to obtain a query result; A first judging module is configured to judge whether the query statement carries a preset keyword; A calling module is configured to call a parser to parse the preset keyword to obtain a filter instruction corresponding to the preset keyword if the query statement carries the preset keyword; A filtering module is configured to filter the query result by the filter instruction to obtain a filtered query result; The step of filtering the query result by the filter instruction to obtain a filtered query result includes: It is judged whether the query statement includes a plurality of filter instructions corresponding to each preset keyword; If the query statement includes multiple filter instructions corresponding to the multiple preset keywords, logical operators between the multiple filter instructions corresponding to the multiple preset keywords are identified; An order of calling the multiple filter instructions corresponding to the multiple preset keywords is sorted according to the logical operators, and an instruction order is formed; The query result is filtered according to the filter instructions corresponding to the multiple preset keywords in sequence according to the instruction order, and a filtered query result is obtained; The step of filtering the query result according to the filter instructions corresponding to the multiple preset keywords in sequence according to the instruction order to obtain the filtered query result includes: It is judged whether the query statement includes a first instruction, wherein the first instruction is included in the filter instructions corresponding to the multiple preset keywords, the first instruction is an instruction for setting data corresponding to a first specified field in the query result as empty, and the first specified field is any field in the query result; If the query statement includes the first instruction, data corresponding to the first specified field in the query result is set as empty according to the first instruction; According to the sorting of all fields in the query result, the remaining fields except the first specified field in the query result are combined into a first query result filtered by the first instruction, and the first query result is included in the filtered query result; Wherein, the filter instructions corresponding to each preset keyword are different, when a preset keyword is connected with a specific field in the query result, the filter instruction corresponding to the preset keyword is executed on the specific field; each preset keyword can be used on a specific field alone or on two or more fields; The step of filtering the query result according to the filter instructions corresponding to the multiple preset keywords in sequence according to the instruction order to obtain the filtered query result includes: It is judged whether the query statement includes a second instruction, wherein the second instruction is included in the filter instructions corresponding to the multiple preset keywords, and the second instruction is an instruction for returning only data corresponding to a second specified field in the query result; If the query statement includes the second instruction, data corresponding to the second specified field in the query result is determined according to the second instruction; The data corresponding to the second specified field is taken as a second query result filtered by the second instruction, and the second query result is included in the filtered query result; The step of filtering the query result according to the filter instructions corresponding to the multiple preset keywords in sequence according to the instruction order to obtain the filtered query result includes: It is judged whether the query statement includes a third instruction, wherein the third instruction is included in the filter instructions corresponding to the multiple preset keywords, and the third instruction is an instruction for converting data in the query result into an array; If the query statement includes the third instruction, data corresponding to each field in the query result is converted into an array according to the third instruction. Assemble the arrays corresponding to the fields into an array combination according to the arrangement order of the fields in the query result; The array combination is taken as a third query result filtered by the third instruction, and the third query result is included in the filtered query result. 5.A computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the computer device is configured to perform the method according to any one of claims 1-6. The processor implements the steps of the method in any one of claims 1 to 4 when executing the computer program.
6. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the method in any one of claims 1 to 4. The computer program is executed by the processor to implement the steps of the method in any one of claims 1 to 4.
Citation Information
Patent Citations
Query method and device based on relational database
CN112765286A