A data screening method, device and product

CN120448386BActive Publication Date: 2026-08-11XIANGYANG QIUJI WIN SOFTWARE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-04-28
Publication Date
2026-08-11

AI Technical Summary

Technical Problem

[0004]由此可知,当前技术中,对于不使用现有数据库软件存储的数据集合来说,缺少一种通用简便的方法实现数据集合的筛选

Benefits of technology

[0043]相较于现有技术,本申请具有以下有益效果:本申请中,通过基于查询对象的实例构建的筛选树即可实现数据筛选,不再需要定制对应的查询代码,避免了人工资源的重复浪费,并且简化了数据筛选的过程。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120448386B_ABST
    Figure CN120448386B_ABST
Patent Text Reader

Abstract

This application discloses a data filtering method, apparatus, and product, relating to the field of data processing technology. The method includes: constructing a corresponding filtering tree based on an instance of a query object; and filtering the data set corresponding to the query object using the corresponding filtering tree to obtain a filtered subset. In this application, the filtering tree is constructed based on an instance of the query object, and each field of the query object is constructed as one or a group of filtering nodes in the filtering tree. The filtering nodes are used to perform logical operations on the elements in the data set to obtain a judgment result, thereby filtering the elements based on the filtering tree. Data filtering can be achieved by using a filtering tree constructed based on an instance of the query object, eliminating the need for customized query code, avoiding redundant waste of manual resources, and simplifying the data filtering process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, and in particular to a data filtering method, apparatus and product. Background Technology

[0002] Data filtering is a fundamental step in data querying, referring to the process of selecting data (elements) from a large amount of data that meets specific conditions to satisfy business needs. For example, in data development, elements of the same type are typically stored in a dataset, and elements that meet specific conditions are filtered from the dataset to fulfill the corresponding business requirements.

[0003] In current technology, for data sets that are not stored using existing database software, it is necessary to manually write code to filter the data set according to business needs.

[0004] Therefore, it can be seen that in current technology, there is a lack of a universal and simple method to filter data sets that are not stored using existing database software. Summary of the Invention

[0005] To address the aforementioned issues, this application provides a data filtering method, apparatus, and product. By defining specific query objects, data filtering can be achieved without the need to write additional query code, thus avoiding the repetitive waste of manual resources and simplifying the data filtering process.

[0006] The embodiments of this application disclose the following technical solutions:

[0007] Firstly, this application provides a data filtering method, including:

[0008] Based on the obtained instance of the query object, a corresponding filter tree is constructed; the fields defined in the query object include at least a first type of field and a second type of field; the first type of field is used to construct a filter node; the second type of field is used to construct a set of filter nodes, the set of filter nodes including a parent node and multiple child nodes; the filter nodes are used to perform logical operations on the elements in the data set to obtain a judgment result; the filter nodes are organized into a tree structure according to the field structure of the query object, which is called a filter tree.

[0009] The corresponding filter tree is used to filter the data set corresponding to the query object to obtain a filter subset.

[0010] Optionally, the first type of field is a field whose name ends with a preset atomic predicate, and the second type of field is a field whose name ends with a preset compound predicate.

[0011] Optionally, constructing a corresponding filter tree based on the obtained instance of the query object includes:

[0012] Based on the instance of the query object, a branch node of the tree structure is constructed as the root node of the filter tree; the branch node includes a logical operator and multiple child nodes; the logical operator is used to perform logical operations on the judgment results returned by the multiple child nodes to obtain the judgment result of the branch node;

[0013] Iterate through the fields of the instance of the query object and construct the child nodes of the branch node from the fields that have been assigned values.

[0014] Optionally, constructing the already assigned field as a child node of the branch node includes:

[0015] Based on the names of the fields that have been assigned values, determine the category of the fields that have been assigned values;

[0016] For the first type of field that has been assigned a value, construct the corresponding leaf node of the tree structure; the leaf node includes a predicate logic that judges the element; the predicate logic is constructed based on the field name and the assigned value;

[0017] For the second type of field that has been assigned a value, construct the corresponding branch node of the tree structure, and construct the child node of the branch node recursively according to the assigned value of the second type of field until all assigned fields have been constructed; the logical operator of the branch node is set according to the compound predicate in the name of the second type of field.

[0018] Optionally, constructing a corresponding filter tree based on the obtained instance of the query object includes:

[0019] Based on the type of the obtained query object, obtain the corresponding filter tree template; the leaf nodes in the filter tree template include predicate logic containing variables, and the branch nodes in the filter tree template do not include child nodes; wherein, the variables are determined based on the assignment of the first type of field, and the child nodes of the branch nodes are determined based on the assignment of the second type of field;

[0020] Based on the instance of the query object and the corresponding filter tree template, construct the corresponding filter tree.

[0021] Optionally, obtaining the corresponding filter tree template based on the type of the obtained query object includes:

[0022] Based on the type of the query object obtained, the corresponding filter tree template is obtained from the context;

[0023] If the corresponding filter tree template is not obtained, a corresponding filter tree template is constructed according to the type of the query object, and the type of the query object, the filter tree template, and their mapping relationship are stored in the context.

[0024] Optionally, constructing a corresponding filter tree template based on the type of the query object includes:

[0025] Based on the type of the query object, construct the branch nodes of the tree structure as the root node of the filter tree template, and traverse all fields defined in the query object;

[0026] For the first type of field, a leaf node is constructed in the filter tree template; wherein, the leaf node in the filter tree template includes predicate logic containing variables; the variables are determined according to the values ​​assigned to the first type of field;

[0027] For the second type of field, construct the branch node in the filter tree template, and continue to construct the filter tree template according to the type of the second type of field. Store the type of the second type of field and the filter tree template and its mapping relationship in the context until a filter tree template is constructed for all known types of the second type of field.

[0028] Optionally, constructing the corresponding filter tree based on the instance of the query object and the corresponding filter tree template includes:

[0029] Based on the instance of the query object, construct the branch nodes of the tree structure as the root node of the filtering tree;

[0030] Iterate through the fields in the instance of the query object, and add the nodes in the filter tree template corresponding to the fields that have been assigned values ​​as child nodes of the branch node;

[0031] For the first type of field that has already been assigned a value, add the leaf node corresponding to the first type of field in the filter tree template as the child node of the branch node, and set the variable to the value assigned to the first type of field that has already been assigned a value;

[0032] For the second type of field that has been assigned a value, add the branch node in the filter tree template corresponding to the second type of field that has been assigned a value as the child node of the branch node; based on the assigned value of the second type of field, recursively construct the child node of the branch node corresponding to the second type of field that has been assigned a value.

[0033] Optionally, the step of filtering the data set corresponding to the query object through the corresponding filter tree to obtain a filter subset includes:

[0034] Iterate through all elements of the data set corresponding to the query object;

[0035] The root node of the filter tree is used to judge each traversed element, and the judgment result is obtained. Elements whose judgment result is true are added to the filter result set.

[0036] After the traversal is complete, output the set of filtered results as the filtered subset.

[0037] Secondly, this application provides a data filtering device, comprising:

[0038] The construction module is used to construct a corresponding filter tree based on the obtained query object instance; the fields defined in the query object include at least a first type of field and a second type of field; the first type of field is used to construct a filter node; the second type of field is used to construct a set of filter nodes, the set of filter nodes including a parent node and multiple child nodes; the filter node is used to perform logical operations on the elements in the data set to obtain a judgment result; the filter nodes are organized into a tree structure according to the field structure of the query object, which is called a filter tree.

[0039] The filtering module is used to filter the data set corresponding to the query object through the corresponding filtering tree to obtain a filtered subset.

[0040] Thirdly, this application provides a data filtering product, including: a processor and a memory, wherein the processor and the memory are coupled;

[0041] The memory is used to store computer program instructions;

[0042] The processor is used to execute computer program instructions stored in the memory to implement the data filtering method described in any of the first aspects above.

[0043] Compared with the prior art, this application has the following advantages: In this application, data filtering can be achieved by constructing a filtering tree based on the instance of the query object, eliminating the need to customize the corresponding query code, avoiding the repeated waste of manual resources, and simplifying the data filtering process. Attached Figure Description

[0044] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0045] Figure 1 A flowchart illustrating a data filtering method provided in an embodiment of this application;

[0046] Figure 2 A flowchart illustrating a method for constructing a filtering tree as provided in an embodiment of this application;

[0047] Figure 3 A flowchart illustrating another method for constructing a filtering tree provided in this application embodiment;

[0048] Figure 4 A flowchart illustrating a method for constructing a filtering tree template provided in an embodiment of this application;

[0049] Figure 5 A structural example diagram of a filtering tree template provided in an embodiment of this application;

[0050] Figure 6 A flowchart illustrating a method for filtering a data set, as provided in an embodiment of this application;

[0051] Figure 7 Example diagram of assigning values ​​to instances of the query object UserQuery provided in the embodiments of this application;

[0052] Figure 8 A structural example diagram of a filter tree and a filter tree template provided in the application embodiment;

[0053] Figure 9 This is a schematic diagram of the structure of a data filtering device provided in an embodiment of this application. Detailed Implementation

[0054] In current technology, for datasets stored using existing database software, data filtering can be accomplished using the database query language corresponding to the database software. For datasets not stored using existing database software (e.g., data structures such as sets or lists in memory), it is necessary to manually write corresponding code based on the element types of each dataset and the data query requirements to achieve data filtering.

[0055] This application provides a data filtering method, including: constructing a corresponding filter tree based on an instance of a query object; and filtering the data set corresponding to the query object through the filter tree to obtain a filtered subset. In this application, the filter tree is constructed based on an instance of the query object, and the fields of the query object are constructed as filter nodes in the filter tree. The filter nodes are used to perform logical operations on the elements in the data set to obtain judgment results, thereby filtering the elements based on the filter tree. Data filtering can be achieved simply by constructing a filter tree based on the instance of the query object, eliminating the need to write additional data filtering code, improving development efficiency, and simplifying the data filtering process.

[0056] Furthermore, there is a correspondence between the query object and the element type; that is, one query object is only applicable to a collection of elements of one type. For a collection of elements of the same type, it is necessary to construct an instance using the corresponding query object and assign values ​​to it. Different filtering requirements are met by assigning different values ​​to the instances of the query object. Although the query objects corresponding to collections of elements of different types are different, the process of constructing the corresponding filter tree based on the instances of the query object is the same, further simplifying the data filtering process.

[0057] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.

[0058] Example 1:

[0059] The following is combined Figures 1-8 This paper will provide a detailed description of a data filtering method provided in the embodiments of this application.

[0060] It should be noted that the data filtering method provided in this application is a data filtering method for general-purpose terminal devices, that is, the method is applied to general-purpose terminal devices. General-purpose terminal devices include: mobile computing terminals, wearable terminals, smart home terminals, and embedded system devices.

[0061] like Figure 1 As shown in the embodiments of this application, a data filtering method includes the following steps:

[0062] S101. Based on the obtained instance of the query object, construct the corresponding filter tree.

[0063] The query objects are predefined based on the attributes of the elements in the dataset and business requirements. In other words, technical personnel define corresponding query objects based on the attributes of the elements in the dataset and the query requirements, which are then used to filter the dataset.

[0064] Furthermore, the type of elements in a data set is a collection of attributes. For example, when the type of an element is "user," its attribute set typically includes: identifier, age, name, occupation, etc. In computer programming terms, the type of an element is a structure or class, and the element contains the specific data corresponding to each attribute. Specifically, for procedural programming languages ​​(e.g., C), the type of an element is a structure (struct), and the element is a structure variable; for object-oriented programming languages ​​(e.g., C++, Java, Python), the type of an element is a class (class), and the element is an instance of that class (instance).

[0065] The query object defines at least two types of fields: a first type and a second type. The first type of fields are used to construct a filter node, and the second type of fields are used to construct a group of filter nodes. A group of filter nodes includes a parent node and multiple child nodes. The filter nodes are organized into a tree structure based on the field structure of the query object, called a filter tree. The filter nodes are used to perform logical operations on the elements in the data set to obtain the judgment result.

[0066] Specifically, the first type of field consists of fields whose names end with a predefined atomic predicate, and the second type consists of fields whose names end with a predefined compound predicate. Atomic predicates are the simplest logical statements and cannot be further broken down into smaller logical parts. Compound predicates are formed by combining one or more atomic predicates or other compound predicates using logical element operators (such as AND, OR, etc.).

[0067] Specifically, a filter tree is a tree structure built based on instances of a query object. Each node in the filter tree is a filter node, used to perform logical operations on the elements in the data set to obtain a judgment result. A tree structure is an important data structure in computer science used to represent data with hierarchical relationships.

[0068] The instance of the query object is created by the computer based on the definition of the query object and assigned values ​​according to the obtained query parameters.

[0069] To make it easier to understand, the following will be combined with... Figures 2-5 The two methods for constructing a filtering tree provided in the embodiments of this application will be described in detail.

[0070] First, combine Figure 2 This application provides a detailed description of a method for constructing a filtering tree, as provided in its embodiments.

[0071] like Figure 2 As shown in the embodiments of this application, a method for constructing a filtering tree includes the following steps:

[0072] S210. Based on the instance of the query object, construct a tree-structured branch node as the root node of the filtering tree.

[0073] A branch node is a node in a tree structure that contains multiple child nodes.

[0074] Specifically, a branch node includes logical operators and multiple child nodes. The branch node is used to perform logical operations on the judgment results returned by its child nodes to obtain the judgment result of the branch node. Logical operators include: AND, OR, NOT, XOR, etc.

[0075] Furthermore, the logical operator for the branch nodes that serve as the root node of the filtering tree is AND.

[0076] It should be noted that the logical operator of the root node of the filter tree corresponding to each instance of the query object is AND.

[0077] S220. Traverse the fields of the instance of the query object and construct the child nodes of the branch node from the fields that have been assigned values.

[0078] Specifically, it iterates through the fields of the instance of the query object, obtains the field assignments through reflection, determines the fields that have been assigned values, and constructs the assigned fields as child nodes of the branch nodes.

[0079] like Figure 2 As shown, constructing a child node of a branch node from an already assigned field involves the following steps:

[0080] S221. Based on the names of the fields that have been assigned values, determine the category of the fields that have been assigned values.

[0081] The fields are categorized into two types: Type 1 fields and Type 2 fields. Type 1 fields are used to construct a single filter node, which is a leaf node in a tree structure. Type 2 fields are used to construct a set of filter nodes, which includes a parent node and multiple child nodes. In other words, Type 2 fields are used to construct branch nodes and their child nodes in a tree structure.

[0082] Fields whose names end with a preset atomic predicate are classified as Class 1 fields, and fields whose names end with a preset compound predicate are classified as Class 2 fields.

[0083] Here, the predefined atomic predicates are predefined words or abbreviations corresponding to the atomic predicate logic. For example, the predefined abbreviation corresponding to the predicate logic "greater than" is Gt (is Greater Than); the predefined abbreviation corresponding to the predicate logic "greater than or equal to" is Ge (is Greater than or Equal to).

[0084] It should be noted that in this embodiment, the first type of field and the second type of field are distinguished by preset atomic predicates and compound predicates. In addition, new field classifications can be added based on other characteristics of the field, such as annotations, specific types, etc. The application does not make specific limitations.

[0085] Furthermore, for fields that cannot be categorized based on their name suffixes and other characteristics, they are defaulted to Category 1 fields, and the predicate suffix is ​​a predefined word corresponding to the predicate logic "equal to" (e.g., "Eq"). For example, the uncategorized fields id and age are processed as equivalent to idEq and ageEq.

[0086] Specifically, fields ending with an atomic predicate are classified as Class 1 fields, and fields whose names end with a compound predicate are classified as Class 2 fields. In particular, when the name of a field does not match a preset predicate, the field is classified as Class 1 field by default, and the corresponding atomic predicate is Eq.

[0087] The logical operators for the branch nodes are Boolean algebra logical operators such as AND, OR, NOT, and XOR. Therefore, the preset set of compound predicates can be {And, Or, Not, Xor}, or variations based on naming rules, such as {_and, _or, _not, _xor}, etc., and this application does not impose any specific limitations.

[0088] For example, when the name of a field ends with a preset atomic predicate such as Gt, Ge, or Contain, the field is a first-type field; when the name of a field ends with a compound predicate such as "Or" or "And", the field is a second-type field.

[0089] For the first type of field that has already been assigned a value, perform S222.

[0090] For the second type of field that has already been assigned a value, proceed with S223.

[0091] S222, Construct the leaf nodes of the corresponding tree structure.

[0092] Leaf nodes have no child nodes. Each leaf node contains a predicate logic that evaluates an element. This predicate logic is used to evaluate the selected element and obtain the evaluation result of the leaf node.

[0093] Specifically, based on the names and values ​​of the first type of fields that have already been assigned, the leaf nodes of the corresponding tree structure are constructed. That is, the attribute name and predicate name are determined based on the names of the first type of fields that have already been assigned, and the predicate logic is constructed based on the attribute name, predicate name, and the assigned values ​​of the first type of fields, thereby obtaining the leaf nodes of the corresponding tree structure.

[0094] The names of the first type of fields are defined based on the attribute predicate expression {x∈A:xP(v)}. The attribute predicate expression {x∈A:xP(v)} is a mathematical formula used in this invention to describe the newly defined names of the first type of fields. Here, A is the set of attributes of an element, x is an attribute in A, P is an atomic predicate in a preset set of atomic predicates (see Table 1 for details), and v is a variable determined by the field assignment. The predicate logic corresponding to xP(v) can be expressed as "the value of attribute x of the element and the variable v satisfy the logical relationship P", or "$x P v". The attribute predicate expression can be abbreviated to xP as the name format of the first type of field. That is, the name format of the first type of field is "<attribute name><predicate name>".

[0095] For example, for the first type of field ageGt(30), where the attribute x is age, the predicate P is Gt, and the variable v is 30, the corresponding predicate logic can be expressed as "the value of the attribute age of the element satisfies the logical relationship greater than that of the variable 30", or "$age is greater than 30".

[0096] For ease of understanding, Table 1 lists a set of predefined atomic predicates and their corresponding predicate logic.

[0097] Table 1

[0098] Eq $x equals v NotLike $x does not include v Ne $x is not equal to v Like $x includes v Gt $x is greater than v NotStart $x does not begin with v Ge $x is greater than or equal to v Start $x starts with v Lt $x is less than v NotEnd $x does not end with v Le $x is less than or equal to v End $x ends in v NotIn $x does not belong to v NotContain $x does not contain v In $x belongs to v Contain $x contains v Null Is $x empty?

[0099] It should be noted that the predicates in the preset atomic predicate set shown in Table 1 are one implementation of the preset atomic predicates described above. In addition to the predicate names shown in Table 1, additional atomic predicates and their corresponding predicate logic can be defined according to the actual situation. Of course, a different set of preset atomic predicates can also be defined according to other naming conventions, which will not be elaborated here.

[0100] For example, an element contains three attributes: id, name, and age, representing the element's identifier, name, and age, respectively. Suppose we need to filter elements whose age is greater than a certain value. The name of the first type of field defined by the attribute predicate expression is ageGt. Specifically, when the first type of field ageGt is assigned the value 30, the steps for constructing the leaf node of the corresponding tree structure are as follows: First, determine the predicate name P as "Gt" based on the attribute predicate expression and Table 1. Remove the predicate name "Gt" from "ageGt" to obtain the attribute name x as "age". After obtaining the value 30 for the first type of field ageGt, determine the corresponding predicate logic as "$age greater than 30" according to Table 1. Therefore, construct the leaf node of the corresponding tree structure for the first type of field ageGt with the assigned value of 30, including the predicate logic "$age greater than 30". When filtering a specific element, obtain the value of the attribute age from the element, substitute it into the predicate logic "$age greater than 30", and execute it to obtain the logical judgment result.

[0101] S223. Construct the corresponding tree structure branch nodes, and recursively construct the child nodes of the branch nodes according to the assigned values ​​of the second type of fields until all assigned fields have been constructed.

[0102] The corresponding branch node is used to perform corresponding logical operations on the judgment results returned by its child nodes based on the logical operators, and obtain the judgment result of the branch node.

[0103] Specifically, when constructing the corresponding branch node for the already assigned second-class field, the logical operator of the branch node is determined based on the compound predicate at the end of the name of the second-class field.

[0104] Specifically, the assignment of the second type of field is used to indicate the instance of the corresponding query object. Then, the child node of the branch node is constructed recursively based on the assigned value of the second type of field. That is, the filter node corresponding to the instance of the query object with the assigned value is constructed recursively based on the assigned value of the second type of field. This filter node is then used as the child node of the branch node corresponding to the assigned value of the second type of field.

[0105] For example, suppose the query object UserQuery has Integer type fields ageGt and ageLe, and a UserQuery type field userOr. Create an instance A of UserQuery, and assign the second type field userOr to another UserQuery query object instance B, and assign values ​​to instance B, where the ageGt field is assigned a value of 5 and the ageLe field is assigned a value of 25. Construct a branch node for instance A as the root node of the filter tree, and construct a tree structure branch node for the userOr field. Based on the compound predicate "Or" of the assigned second type field, set the logical operator of the branch node to "OR" to construct the corresponding branch node 1; when the first type field ageGt is assigned a value of 5, first determine the predicate name P as "Gt" based on the attribute predicate expression, remove the predicate name "Gt" from "ageGt" to obtain the attribute name x as "age", and after obtaining the first type field ageGt's assigned value of 5, determine the corresponding predicate logic as "$age is greater than 5", and then construct the corresponding branch node for the first type field ageGt with a value of 5. Leaf node 2 includes the predicate logic "$age is greater than 5". Similarly, for the first type field ageLe, which is assigned a value of 25, the predicate name P is first determined to be "Le" based on the attribute predicate expression. The predicate name "Le" is then removed from "ageLe" to obtain the attribute name x as "age". After obtaining the first type field ageLe's assigned value of 25, the corresponding predicate logic is determined to be "$age is less than or equal to 25". Therefore, leaf node 3 is constructed for the first type field ageLe with an assigned value of 25, including the predicate logic "$age is less than or equal to 25". Furthermore, in instance B indicated by the already assigned second type field userOr, all assigned fields have been constructed, thus completing the construction of the branch node for userOr.

[0106] Furthermore, in one possible implementation, the field type of the second type of field indicates the type of the query object, that is, it indicates the corresponding query object, and the assignment of the second type of field is used to indicate the instance of the corresponding query object.

[0107] In one possible implementation, the name of the second type of field is formatted as the element name plus a compound predicate suffix.

[0108] The above combination Figure 2 A detailed explanation of a method for constructing a filter tree corresponding to instances of a query object is provided below. Figures 3-5 This paper will now describe in detail another method for constructing a filter tree provided in the embodiments of this application.

[0109] like Figure 3 As shown, another method for constructing a filtering tree provided in this application embodiment includes the following steps:

[0110] S310. Obtain the corresponding filter tree template based on the type of the obtained query object.

[0111] There is a one-to-one mapping relationship between the type of the query object and the filter tree template.

[0112] The leaf nodes in the filter tree template include predicate logic containing variables, while the branch nodes do not include child nodes. The variables are determined based on the values ​​assigned to the first type of fields, and the child nodes of the branch nodes are determined based on the values ​​assigned to the second type of fields.

[0113] Specifically, the filter tree template is constructed based on the type of the query object. Therefore, the filter tree template contains leaf nodes corresponding to all first-type fields defined in the query object and branch nodes (excluding child nodes) corresponding to all second-type fields. Since the query object type does not include field assignments, and the variables in the predicate logic are determined based on the assignments of the first-type fields, the leaf nodes in the filter tree template include predicate logic containing variables. Similarly, since the child nodes of the branch nodes are determined based on the assignments of the second-type fields, the branch nodes in the filter tree template do not include child nodes.

[0114] In one possible implementation, the corresponding filter tree template is obtained from the context based on the type of the obtained query object; if the corresponding filter tree template is not obtained, the corresponding filter tree template is constructed according to the type of the query object, and the type of the query object, the filter tree template and their mapping relationship are stored in the context so that the filter tree template corresponding to the type of the query object can be obtained from the context next time.

[0115] To make it easier to understand, the following will be combined with... Figure 4 Here is a detailed explanation of how to construct the corresponding filter tree template.

[0116] S401. Based on the type of the query object, construct a tree-structured branch node as the root node of the filter tree template, and traverse all fields defined in the query object.

[0117] The logical operator for filtering the root node of the tree template (i.e., the branch node of the constructed tree structure) is AND.

[0118] Specifically, it iterates through all fields defined in the query object to determine the category of each field, i.e., to determine the first category and the second category of fields. For example, the category of fields is determined based on the names of the fields defined in the query object: fields whose names end with a preset atomic predicate are classified as first category fields, and fields whose names end with a preset compound predicate are classified as second category fields.

[0119] For the first type of field, proceed with S402.

[0120] For the second type of field, S403 is performed.

[0121] S402, Construct the leaf nodes in the filter tree template.

[0122] The leaf nodes in the filter tree template contain predicate logic with variables, which are determined by the assignment of the first type of fields. The predicate logic is expressed as "the value of attribute x of an element satisfies the logical relationship P with variable v". Variable v is determined by the assignment of the first type of fields. Since all fields in the query object are unassigned, the predicate logic in the leaf nodes of the filter tree template contains variables, i.e., variable v is empty.

[0123] For example, if query object A defines a first-class field "idGt" based on the attribute predicate expression, then the name P of the atomic predicate is determined to be "Gt" based on the attribute predicate expression. Removing the name "Gt" of the atomic predicate from "idGt" yields the attribute name x as "id". Then, leaf node A in the filter tree template is constructed. Leaf node A in the filter tree template includes the predicate logic "$id is greater than #idGt" containing variables, where "#idGt" is a variable indicating the assignment of the first-class field "idGt".

[0124] S403. Construct branch nodes in the filter tree template, and continue to construct the filter tree template according to the type of the second type of field. Store the type of the second type of field and the filter tree template and their mapping relationship in the context until a filter tree template is constructed for all known types of the second type of field.

[0125] In this context, branch nodes that are child nodes in the filter tree template do not include child nodes. That is, for the second type of field, after constructing it as a branch node in the filter tree template, no further child nodes are constructed for it. Instead, it checks whether a filter tree template corresponding to this type is stored in the context; if it does not exist, a new filter tree template is constructed based on this type.

[0126] Specifically, when constructing the corresponding branch node in the filter tree template for the second type of field, the logical operator of the corresponding branch node in the filter tree template is determined based on the compound predicate at the end of the name of the second type of field.

[0127] To make it easier to understand, the following will be combined with... Figure 5 Let me give you an example of a filter tree template.

[0128] Suppose that the query object B defines the fields idLt, nameStart, ageGt, userAnd, and userOr.

[0129] like Figure 5The filter tree template shown is a filter tree template constructed based on the type of query object B.

[0130] Create branch node 501 (default logical operator is AND) as the root node of the filter tree template.

[0131] For the first type of field, the predicate name P is determined to be "Lt" based on the attribute predicate expression "idLt". The attribute name x is obtained by removing the predicate name "Lt" from "idLt". Then, leaf node 502 of the filter tree template is constructed. Leaf node 502 includes the predicate logic "$id is less than #idLt" (#idLt is the actual value assigned to the first type of field idLt). The predicate name P is determined to be "Start" based on the attribute predicate expression "nameStart". The attribute name x is obtained by removing the predicate name "Start" from "nameStart". Then, the filter tree template is constructed. Leaf node 503 in the filter tree template includes the predicate logic "$name starts with #nameStart" (#nameStart is the actual value of the first type field nameStart); the predicate name P is determined to be "Gt" based on the attribute predicate expression "ageGt", and the attribute name x is obtained by removing the predicate name "Gt" from "ageGt". Then, leaf node 504 of the filter tree template is constructed, which includes the predicate logic "$age is greater than #ageGt" (#ageGt is the actual value of the first type field ageGt).

[0132] For the second type of field, based on the second type of field "userAnd" and the compound predicate "And", branch node 505 is created in the filter tree template, and the logical operator of branch node 505 is the AND logical operator; based on the second type of field "userOr" and the compound predicate "Or", branch node 506 is created in the filter tree template, and the logical operator of branch node 506 is the OR logical operator.

[0133] The above combination Figure 4 and Figure 5 This paper details how to create a filter tree template in the embodiments of this application. The following section will continue with further examples. Figure 3 This paper introduces another method for constructing a filter tree in the embodiments of this application.

[0134] S320. Based on the instance of the query object and the corresponding filter tree template, construct the corresponding filter tree.

[0135] like Figure 3 As shown, constructing the corresponding filter tree based on the instance of the query object and the corresponding filter tree template includes the following steps:

[0136] S321. Based on the instance of the query object, construct a tree-structured branch node as the root node of the filtering tree.

[0137] S322. Traverse the fields in the instance of the query object and add the nodes in the filter tree template corresponding to the fields that have been assigned values ​​as child nodes of the branch nodes.

[0138] Specifically, for the first type of field that has already been assigned a value, add the node corresponding to the first type of field in the filter tree template as the child node of the current branch node, and set the variable in the predicate logic to the value of the first type of field that has already been assigned a value, so as to obtain the leaf node corresponding to the first type of field that has already been assigned a value.

[0139] For example, the predicate logic of the leaf node corresponding to "idLt" in the filter tree template includes the variable "$id is less than #idLt". If the value of "idLt" in the query object instance is 20, then the predicate logic of the leaf node corresponding to the assigned "idLt" is "$id is less than 20".

[0140] Specifically, for the second type of field that has been assigned a value, add the node corresponding to the assigned second type of field in the filter tree template as the child node of the current branch node, and construct the child node of the corresponding branch node recursively based on the assigned value of the second type of field.

[0141] For example, such as Figure 5 The image shows a filter tree template constructed based on the type of query object B. If the `userOr` field in an instance of query object B is a second-type field that has already been assigned a value, then branch node 506 corresponding to `userOr` in the filter tree template is added as a child node of the root node of the filter tree. If, based on the assigned value of the `userOr` field, it is determined to be another instance of query object B, then the filter tree template corresponding to the type of query object B is retrieved again, and the process is recursively repeated to construct child nodes of the branch node corresponding to the `userOr` field (i.e., branch node 506 added to the filter tree) based on the instance of query object B and its corresponding filter tree template.

[0142] The above combination Figures 2-5 This paper details two methods for constructing a filtering tree provided in the embodiments of this application. The following section will continue to discuss these methods in conjunction with... Figure 1 This application introduces a data filtering method provided by an embodiment.

[0143] S102. By using the filter tree, the data set corresponding to the query object is filtered to obtain the filtered subset.

[0144] In this system, there is a correspondence between the query object and the element type in the data set. For example, if the query object C is predefined based on the car type, then a filter tree c is constructed based on the obtained instances of the query object C. This filter tree c is used to filter the data set whose element type is car, resulting in a filtered subset. In other words, the filter tree constructed using instances of the query object is used to filter the data set of the element type corresponding to that query object.

[0145] The correspondence between the query object and the element type in the data set exists because the 'x' in the name format (i.e., attribute predicate expression) xP of the first type field of the query object comes from the element's attribute. In implementation, there are multiple ways to determine the corresponding data set for each instance of the query object:

[0146] The first method is to simultaneously obtain the instance of the query object and the type of the element, and determine the corresponding data set based on the type of the element; the second method is to simultaneously obtain the instance of the query object and the corresponding data set; the third method is to obtain the instance of the query object and obtain the corresponding data set based on the type of the element declared in the metadata of the query object; the fourth method is to obtain the instance of the query object and determine the corresponding data set based on the context of the method being called.

[0147] It should be noted that, in addition to the four methods mentioned above for determining the corresponding data set for an instance of a query object, there are other methods that can also determine the corresponding data set for an instance of a query object, and this application does not make any specific limitations.

[0148] It should be noted that the data filtering in this application embodiment is actually filtering the elements in the data set.

[0149] To make it easier to understand, the following will be combined with... Figure 6 This paper will provide a detailed description of how the embodiments of this application filter the data set corresponding to the query object.

[0150] like Figure 6 As shown, the filtering of the data set corresponding to the query object in this embodiment includes the following steps:

[0151] S601, Traverse all elements of the data set corresponding to the query object.

[0152] Traversal refers to the process of accessing all elements in a dataset. Specifically, it involves accessing each element in the dataset corresponding to the query object in a specific order. The traversal order determines the order in which the elements are accessed.

[0153] S602. Use the root node of the filter tree to judge each traversed element, obtain the judgment result, and add the elements with the judgment result of true to the filter result set.

[0154] The filtering result set is used to store elements that meet the filtering criteria.

[0155] Specifically, the currently traversed element is input into the root node of the filter tree so that the filter tree can filter the currently traversed element, and the root node of the filter tree returns the judgment result of the currently traversed element.

[0156] The judgment result includes true and false. Elements with a true judgment result are elements that pass the filter, that is, elements that meet the requirements corresponding to the instance of the query object; elements with a false judgment result are elements that fail the filter, that is, elements that do not meet the requirements corresponding to the instance of the query object. After obtaining the judgment result, elements with a true judgment result are added to the filter result set, and elements with a false judgment result are removed.

[0157] In one possible implementation, after a branch node obtains the traversed element, it passes the element to each child node for logical operations to obtain a judgment result. Then, based on the logical operators of the branch node, it performs logical operations on the judgment results returned by each child node to obtain the judgment result of the branch node. The filtering tree uses a method similar to a depth-first search algorithm, starting from the root node and passing the current element to each node for logical operations. Finally, the judgment result of the currently traversed element is returned through the root node of the filtering tree.

[0158] It's important to note that in the filter tree architecture, whether it's a branch node or a leaf node (i.e., all filter nodes), the basis for judging the currently traversed element is the built-in logic unit. That is, all filter nodes use the same core logic program to implement their judgment function for the currently traversed element. Simply put, a filter node first receives the currently traversed element through a built-in, general logic unit, and then performs the corresponding logical operation on that element. The only difference lies in the specific logical operation performed by different filter nodes, allowing them to implement different logical operations.

[0159] S603. After the traversal is complete, output the set of filtered results as the filtered subset.

[0160] Specifically, after traversing all elements in the data set corresponding to the query object, the filtered result set including all elements whose judgment result is true is output as the filtered subset, thus completing the filtering of the data set corresponding to the query object.

[0161] The above combination Figures 1-6 This application provides a detailed description of a data filtering method based on its embodiments. For ease of understanding, the following section combines... Figure 7 and Figure 8Here is an example of a data filtering method based on the Java language provided in this application.

[0162] Suppose that an element of type UserEntity contains three attributes: id, name, and age. Define a corresponding query object UserQuery for the element type UserEntity. The query object UserQuery defines the fields idEq, nameStart, ageGt, userAnd, and userOr. The specific code is shown below:

[0163]

[0164]

[0165] Users Figure 7 The code demonstrates creating an instance of the UserQuery object and assigning values. Solid lines represent fields that have been assigned values, while dashed lines represent fields that have not been assigned values.

[0166] like Figure 8 The filter tree 800 corresponding to the instance of the query object UserQuery shown in (a) is described below with examples of two ways to construct the filter tree.

[0167] The first method for constructing the filtering tree is: based on, for example... Figure 7The example query object UserQuery is used to create a tree-structured branch node 801, with the logical operator AND, serving as the root node of the filter tree 800. All fields of the UserQuery instance are traversed, and reflection reveals that only userOr has been assigned a value. Based on the field suffix "Or", userOr is determined to be a second-class field with an assigned value. Therefore, branch node 802 is constructed based on the second-class field userOr, with the logical operator OR, serving as a child node of branch node 801. The assignment of userOr indicates the UserQuery instance. All fields of this instance are traversed, and reflection reveals that the field idEq is assigned a value of 4, and the field userAnd and its assigned value are read. Based on the field suffix "Eq", idEq is determined to be a first-class field with an assigned value. Based on the field name idEq and its assigned value of 4, the corresponding leaf node 803 is constructed as a child node of branch node 802, and leaf node 803 includes the predicate logic "$id equals 4". The suffix "And" indicates that the field `userAnd` is a second-class field that has already been assigned a value. Therefore, branch node 804 is created as a child node of branch node 802 based on the already assigned second-class field `userAnd`, and the logical operator of branch node 804 is AND. The assignment of `userAnd` indicates an instance of the query object `UserQuery`. Therefore, all fields of this instance are traversed, and the assignment of the field `nameStart` to "Bra" and the assignment of the field `ageGt` to 5 are read through reflection. Based on the field suffix "Start", the field `nameStart` is determined to be a first-class field that has already been assigned a value. Then, based on the field name `nameStart` and its assignment "Bra", the corresponding leaf node 805 is constructed as a child node of branch node 804. Leaf node 805 includes the predicate logic "$name starts with Bra". Based on the field suffix "Gt", the field `ageGt` is determined to be a first-class field that has already been assigned a value. Then, based on the field name `ageGt` and its assignment 5, the corresponding leaf node 806 is constructed as a child node of branch node 804. Leaf node 806 includes the predicate logic "$age is greater than 5". The filter tree construction process ends when all fields in the instance have been traversed, that is, when all assigned values ​​in the second category fields have been traversed.

[0168] Before illustrating the second method of constructing a filter tree with examples, such as... Figure 8As shown in (b), the filter tree template 810 corresponds to the query object UserQuery. The filter tree template 810 includes branch node 811 as the root node of the filter tree template 810, leaf node 812 as the leaf node corresponding to the idEq field in the filter tree template 810, leaf node 813 as the leaf node corresponding to the nameStart field in the filter tree template 810, leaf node 814 as the leaf node corresponding to the ageGt field in the filter tree template 810, branch node 815 as the branch node corresponding to userAnd (logical operator is AND) in the filter tree template 810, and branch node 816 as the branch node corresponding to userOr (logical operator is OR) in the filter tree template 810.

[0169] The first method for constructing the filter tree is as follows: based on... Figure 7 The type of the query object UserQuery is shown, and the corresponding filter tree template 810 is obtained (e.g., ...). Figure 8 (as shown in (b) of the template); based on, Figure 7The query object UserQuery instance is shown. Branch node 801 is created, and the logical operator for branch node 801 is AND, serving as the root node of filter tree 800. All fields of the query object UserQuery instance are traversed. The assigned field userOr and its value are read using reflection. Based on the field suffix "Or", userOr is determined to be a second-type field with an assigned value. Therefore, based on the assigned second-type field userOr, branch node 816 corresponding to userOr is added to filter tree template 810 as branch node 802 (a child node of root node 801). The assignment of userOr indicates the query... An instance of the UserQuery object is used, and all fields of this instance are traversed. Reflection is used to read the field idEq, which is assigned the value 4, and the field userAnd, along with its assigned value. Based on the field suffix "Eq", idEq is determined to be a first-class field with an assigned value. Then, based on the field name idEq and its assigned value 4, leaf node 812 corresponding to idEq in the filter tree template 810 is added as a child node of branch node 802. The assigned value 4 is substituted into the predicate logic variable to obtain leaf node 803, which includes the predicate logic "$id equals 4". Based on the field suffix "And", userAnd is determined to be a second-class field with an assigned value. For the field, based on the already assigned value of the second-type field `userAnd`, add branch node 815 corresponding to `userAnd` in the filter tree template 810 as branch node 804 (a child node of branch node 802); the assignment of `userAnd` indicates an instance of the query object `UserQuery`, so it iterates through all fields of this instance, and through reflection, reads that the field `nameStart` is assigned the value "Bra" and the field `ageGt` is assigned the value 5; based on the field suffix "Start", it is determined that the field `nameStart` is a first-type field that has already been assigned a value, so based on the field name `nameStart` and its assigned value "Bra", add a filter tree template In template 810, leaf node 813 corresponding to nameStart is added as a child node of branch node 804, and the value "Bra" is substituted into the predicate logic variable to obtain leaf node 805. Leaf node 805 includes the predicate logic "$name starts with Bra". Based on the field suffix "Gt", the field ageGt is determined to be a first-class field that has already been assigned a value. Then, based on the field name ageGt and its assigned value 5, leaf node 814 corresponding to ageGt in the filter tree template 810 is added as a child node of branch node 804, and the assigned value 5 is substituted into the predicate logic variable to obtain leaf node 806. Leaf node 806 includes the predicate logic "$age is greater than 5". The filter tree construction is complete.

[0170] Taking the element {id:2,name:"Bravo",age:12} corresponding to the type UserEntity as an example, this illustrates how... Figure 8 The filtering tree shown in (a) in the figure judges the element.

[0171] The element is passed to branch node 801, the judgment process is executed, and the judgment result is obtained. Branch node 801 needs to obtain the judgment result of its child node for a logical AND operation, so branch node 801 passes the element to branch node 802, the judgment process is executed, and the judgment result of branch node 802 is obtained. Branch node 802 passes the element to leaf node 803 and branch node 804, the judgment process is executed, and the judgment results of leaf node 803 and branch node 804 are obtained respectively. When leaf node 803 executes the judgment process, it reads the value of id from the element as 2, that is, $id = 2, so the judgment result of leaf node 803 "$id equals 4" is false. Branch node 804 needs to obtain the judgment result of its child node for a logical AND operation, so branch node 804 passes the element to leaf node 805 and leaf node 806, the judgment process is executed, and the judgment results of leaf node 805 and leaf node 806 are obtained respectively. The results are as follows: When leaf node 805 performs the judgment process, it reads the value of the attribute name from the element as "Bravo", that is, $name = "Bravo", so the judgment result of leaf node 805 "$name starts with Bra" is true; When leaf node 806 performs the filtering process, it reads the value of the attribute age from the element as 12, that is, $age = 12, so the judgment result of leaf node 806 "$age is greater than 5" is true; Therefore, the logical operation "true AND true" of branch node 804 makes the judgment result of branch node 804 itself true; The logical operation "false OR true" of branch node 802 makes the judgment result of branch node 802 itself true; Branch node 801 has only branch node 802 as a child node. Since the judgment result of branch node 802 is true, the judgment result of branch node 801 is true, so the judgment result of the element is true, and it is added to the filtering result set.

[0172] Furthermore, in one possible implementation, the name suffix of the second type of field is a compound predicate, and the field type of the second type of field is an array or set, where the elements of the array or set are of any query object type. For example, the second type of field is a `userOr` field, and its type is List. <userquery>For the userOr field, construct a branch node for it, with the logical operator "OR" for the branch node; construct a branch node for each instance in the UserQuery list corresponding to the field's assigned value, with the logical operator "AND" for the branch node; repeat the process of constructing the assigned field as a child node of the branch node for each instance until all instances have been constructed.

[0173] Furthermore, in another possible implementation, the name suffix of the second type of field is a compound predicate, and the field type of the second type of field is an array or set, where the elements of the array or set are of basic data types. For example, the second type of field is a `nameStartOr` field, and its type is List. <string>For the `nameStartOr` field, construct branch nodes for it, and the logic operation of the branch nodes is "OR"; construct each element in the list corresponding to the assignment of the `nameStartOr` field as a leaf node; determine the attribute predicate expression by removing the compound predicate "Or" from the field name, that is, the name `nameStartOr` becomes `nameStart` after removing "Or", thus the predicate logic of each leaf node can be determined as "$name starts with v", where v is the value of each element in the list corresponding to the assignment of the `nameStartOr` field.

[0174] This application provides a data filtering method, including: constructing a corresponding filter tree based on an acquired instance of a query object; and filtering the data set corresponding to the query object through the filter tree to obtain a filtered subset. In this application, a filter tree is constructed based on an instance of the query object. Each assigned field of the query object is constructed as one or a group of filter nodes in the filter tree. The filter nodes are used to perform logical operations on the elements in the data set to obtain a judgment result, thereby filtering the elements based on the filter tree. In this application, data filtering can be achieved simply by constructing a filter tree based on an instance of the query object, eliminating the need to write additional query code, avoiding redundant waste of manual resources, and simplifying the data filtering process.

[0175] Example 2:

[0176] The following is combined Figure 9 This application provides a detailed description of a data filtering device provided in its embodiments.

[0177] like Figure 9 As shown in the figure, a data filtering device provided in this application embodiment includes the following modules:

[0178] Module 901 is used to construct a corresponding filter tree based on the obtained query object instance; the fields defined in the query object include a first type of field and a second type of field; the first type of field is used to construct a filter node; the second type of field is used to construct a set of filter nodes, a set of filter nodes includes a parent node and multiple child nodes; the filter nodes are used to perform logical operations on the elements in the data set to obtain the judgment result; the filter nodes are organized into a tree structure according to the structure of the query object, which is called the filter tree.

[0179] The filtering module 902 is used to filter the data set corresponding to the query object through the corresponding filtering tree to obtain the filtered subset.

[0180] In one possible implementation, building module 901 includes a first building module and a second building module. The first building module includes a root node building module and child node building modules.

[0181] The root node construction module is used to construct branch nodes in a tree structure based on instances of the query object; the branch nodes constructed based on instances of the query object serve as the root nodes of the filter tree; the branch nodes include logical operators and multiple child nodes; the logical operators are used to perform logical operations on the judgment results returned by multiple child nodes to obtain the judgment result of the branch node;

[0182] The child node building module is used to traverse the fields of the query object instance and build the assigned fields into child nodes of the branch node.

[0183] In one possible implementation, the child node construction module is specifically used to determine the category of the assigned fields based on the names of the assigned fields. Fields whose names end with a preset compound predicate are classified as second-category fields, and fields whose names end with a preset atomic predicate are classified as first-category fields. For the assigned first-category fields, leaf nodes of the corresponding tree structure are constructed. Each leaf node includes a predicate logic that evaluates the element. The predicate logic is constructed based on the field name and the assigned value. For the assigned second-category fields, branch nodes of the corresponding tree structure are constructed, and child nodes of the branch nodes are constructed recursively based on the assigned values ​​of the assigned second-category fields until all assigned second-category fields have been constructed. The logical operators of the branch nodes are set according to the compound predicate in the name of the second-category field.

[0184] In one possible implementation, the second building module includes a template acquisition module and a template instantiation module.

[0185] The template acquisition module is used to obtain the corresponding filter tree template based on the type of the query object. The leaf nodes in the filter tree template include predicate logic containing variables, and the branch nodes in the filter tree template do not include child nodes. The variables are determined based on the assignment of the first type of field, and the child nodes of the branch nodes are determined based on the assignment of the second type of field.

[0186] The template instantiation module is used to construct the corresponding filter tree based on the instance of the query object and the corresponding filter tree template.

[0187] In one possible implementation, the template acquisition module is specifically used to obtain the corresponding filter tree template from the context based on the type of the obtained query object; the second construction module also includes: a template construction module, which is used to construct the corresponding filter tree template according to the type of the query object when the corresponding filter tree template is not obtained, and store the type of the query object, the filter tree template and their mapping relationship in the context.

[0188] In one possible implementation, the template construction module is specifically used to construct branch nodes of a tree structure based on the type of the query object, serving as the root node of the filter tree template, and traversing all fields defined in the query object; for the first type of field, it is constructed as a leaf node in the filter tree template; wherein, the leaf node in the filter tree template includes predicate logic containing variables; the variables are determined based on the assignment of the first type of field; for the second type of field, it is constructed as a branch node in the filter tree template, and the corresponding filter tree template is searched from the context based on the type of the second type of field; if it is not found, the filter tree template is constructed again, and the type of the second type of field and the filter tree template are stored in the context in correspondence, until the filter tree template is constructed for all types of the second type of field.

[0189] In one possible implementation, the template instantiation module is specifically used to construct branch nodes of a tree structure based on the instance of the query object, serving as the root node of the filter tree; traverse the fields in the instance of the query object, adding the nodes in the filter tree template corresponding to the assigned fields as child nodes of the branch nodes; for the assigned first type of field, set the variable in the leaf node corresponding to the assigned first type of field to the assigned value of the assigned first type of field; for the assigned second type of field, construct the child nodes of the branch nodes corresponding to the assigned second type of field recursively based on the assigned value of the second type of field.

[0190] In one possible implementation, the filtering module 902 is specifically used to traverse all elements of the data set corresponding to the query object; use the root node of the filtering tree to judge each traversed element, obtain the judgment result, and add the elements with the judgment result being true to the filtering result set; wherein, the filtering result set is used to store the elements that meet the filtering conditions; after the traversal is completed, the filtering result set is output as the filtering subset.

[0191] This application provides a data filtering device, including: a construction module 901, used to construct a corresponding filtering tree based on an instance of a query object; and a filtering module 902, used to filter the data set corresponding to the query object through the corresponding filtering tree to obtain a filtered subset. In this application, a corresponding filtering tree is constructed based on an instance of the query object. Each field of the query object is constructed as one or a group of filtering nodes in the filtering tree. The filtering nodes are used to perform logical operations on the elements in the data set to obtain a judgment result, thereby filtering the elements based on the filtering tree. Data filtering can be achieved by constructing a filtering tree based on an instance of the query object, eliminating the need to write additional query code, avoiding redundant waste of manual resources, and simplifying the data filtering process.

[0192] In addition, this application also provides a data filtering product, including: a processor and a memory, the processor being coupled to the memory, the memory storing computer-executable instructions, and the processor executing the computer-executable instructions to implement the data filtering method described above.

[0193] This application also provides a computer-readable storage medium storing a computer program that, when run on a computer, causes the computer to perform the data filtering method described in the above embodiments.

[0194] It should be noted that the various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for the method and apparatus embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiments. The method and apparatus embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components indicated as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of the solution in this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.

[0195] The above description is merely one specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.< / string> < / userquery>

Claims

1. A data filtering method, characterized in that, include: Based on the obtained instance of the query object, construct the corresponding filter tree; The fields defined in the query object include at least the first type of fields and the second type of fields; The field type of the second type of field is the query object type; the first type of field is used to construct a filter node; the second type of field is used to construct a set of filter nodes, the set of filter nodes includes a parent node and multiple child nodes, the parent node includes logical operators, and the multiple child nodes are constructed recursively; the filter node is used to perform logical operations on the elements in the data set to obtain the judgment result; The filtering nodes are organized into a tree structure based on the field structure of the query object, and are called a filtering tree; By using the corresponding filter tree, the data set corresponding to the query object is directly filtered to obtain a filter subset; The step of constructing a corresponding filter tree based on the obtained query object instance includes: Based on the instance of the query object, a branch node of the tree structure is constructed as the root node of the filter tree; the branch node includes a logical operator and multiple child nodes; the logical operator is used to perform logical operations on the judgment results returned by the multiple child nodes to obtain the judgment result of the branch node; Iterate through the fields of the instance of the query object and construct the child nodes of the branch node from the fields that have been assigned values; The step of constructing the already assigned fields as child nodes of the branch node includes: Based on the names of the fields that have been assigned values, determine the category of the fields that have been assigned values; For the first type of field that has been assigned a value, construct the corresponding leaf node of the tree structure; the leaf node includes a predicate logic that judges the element; the predicate logic is constructed based on the name and assigned value of the first type of field; For the second type of field that has been assigned a value, construct the corresponding branch node of the tree structure, and construct the child node of the branch node recursively according to the assigned value of the second type of field until all assigned fields have been constructed; the logical operator of the branch node is set according to the compound predicate in the name of the second type of field.

2. The method according to claim 1, characterized in that, The first type of field is a field whose name ends with a preset atomic predicate, and the second type of field is a field whose name ends with a preset compound predicate.

3. The method according to claim 1, characterized in that, The step of constructing a corresponding filter tree based on the obtained query object instance includes: Based on the type of the obtained query object, obtain the corresponding filter tree template; the leaf nodes in the filter tree template include predicate logic containing variables, and the branch nodes in the filter tree template do not include child nodes; wherein, the variables are determined based on the assignment of the first type of field, and the child nodes of the branch nodes are determined based on the assignment of the second type of field; Based on the instance of the query object and the corresponding filter tree template, construct the corresponding filter tree.

4. The method according to claim 3, characterized in that, The step of obtaining the corresponding filter tree template based on the type of the obtained query object includes: Based on the type of the query object obtained, the corresponding filter tree template is obtained from the context; If the corresponding filter tree template is not obtained, a corresponding filter tree template is constructed according to the type of the query object, and the type of the query object, the filter tree template, and their mapping relationship are stored in the context.

5. The method according to claim 4, characterized in that, The step of constructing a corresponding filter tree template based on the type of the query object includes: Based on the type of the query object, construct the branch nodes of the tree structure as the root node of the filter tree template, and traverse all fields defined in the query object; For the first type of field, a leaf node is constructed in the filter tree template; wherein, the leaf node in the filter tree template includes predicate logic containing variables; the variables are determined according to the values ​​assigned to the first type of field; For the second type of field, construct the branch node in the filter tree template, and continue to construct the filter tree template according to the type of the second type of field. Store the type of the second type of field and the filter tree template and its mapping relationship in the context until a filter tree template is constructed for all known types of the second type of field.

6. The method according to claim 3, characterized in that, The step of constructing a corresponding filter tree based on the instance of the query object and the corresponding filter tree template includes: Based on the instance of the query object, construct the branch nodes of the tree structure as the root node of the filtering tree; Iterate through the fields in the instance of the query object, and add the nodes in the filter tree template corresponding to the fields that have been assigned values ​​as child nodes of the branch node; For the first type of field that has already been assigned a value, add the leaf node corresponding to the first type of field in the filter tree template as the child node of the branch node, and set the variable to the value assigned to the first type of field that has already been assigned a value; For the second type of field that has been assigned a value, add the branch node in the filter tree template corresponding to the second type of field that has been assigned a value as the child node of the branch node; based on the assigned value of the second type of field, recursively construct the child node of the branch node corresponding to the second type of field that has been assigned a value.

7. The method according to claim 1, characterized in that, The step of filtering the data set corresponding to the query object through the corresponding filter tree to obtain a filter subset includes: Iterate through all elements of the data set corresponding to the query object; The root node of the filter tree is used to judge each traversed element, and the judgment result is obtained. Elements whose judgment result is true are added to the filter result set. After the traversal is complete, output the set of filtered results as the filtered subset.

8. A data filtering device, characterized in that, include: The building module is used to construct the corresponding filter tree based on the instance of the retrieved query object; The fields defined in the query object include at least a first type of field and a second type of field; the field type of the second type of field is the query object type; the first type of field is used to construct a filter node; the second type of field is used to construct a set of filter nodes, the set of filter nodes includes a parent node and multiple child nodes, the parent node includes logical operators, and the multiple child nodes are constructed recursively; the filter node is used to perform logical operations on the elements in the data set to obtain a judgment result. The filtering nodes are organized into a tree structure based on the field structure of the query object, and are called a filtering tree; The filtering module is used to directly filter the data set corresponding to the query object through the corresponding filtering tree to obtain a filtered subset; The building module includes: a first building module, which includes: a root node building module and a child node building module; The root node construction module is used to construct branch nodes of the tree structure based on the instance of the query object, which serve as the root node of the filter tree; the branch node includes logical operators and multiple child nodes; the logical operators are used to perform logical operations on the judgment results returned by the multiple child nodes to obtain the judgment result of the branch node; The child node construction module is used to traverse the fields of the instance of the query object and construct the assigned fields as child nodes of the branch node. The child node construction module is specifically used for: Based on the names of the fields that have been assigned values, determine the category of the fields that have been assigned values; For the first type of field that has been assigned a value, construct the corresponding leaf node of the tree structure; the leaf node includes a predicate logic that judges the element; the predicate logic is constructed based on the name and assigned value of the first type of field; For the second type of field that has been assigned a value, construct the corresponding branch node of the tree structure, and construct the child node of the branch node recursively according to the assigned value of the second type of field until all assigned fields have been constructed; the logical operator of the branch node is set according to the compound predicate in the name of the second type of field.

9. A data filtering product, characterized in that, include: A processor and a memory, wherein the processor and the memory are coupled; The memory is used to store computer program instructions; The processor is used to execute computer program instructions stored in the memory to implement the data filtering method according to any one of claims 1-7.

Citation Information

Patent Citations

  • SQL (Structured Query Language) query visual configuration method and system for screening data as required

    CN118626532A

  • Searching method and device, equipment and storage medium

    CN119201972A