US 5,428,737 AGrant
Comprehensive Bilateral Translation Between SQL and Graphically Depicted Queries
Issue Date:1995-06-27
•14 Claims
•41 Drawing Sheets
Abstract
A method, system and program providing comprehensive bilateral translation between text format and visual format relational database queries. In a preferred form, tables and lists are configured to define a common data structure. Translation between structured query language (SQL) query statements and the common data structure is accomplished by clause. Similarly, a common data structure for the visual or graphical format queries is defined, preferably employing graphics symbols and multiple windows. Bidirectional translation is thereafter accomplished through the common data structure. The method, system and program is comprehensive in the SQL clauses available, together with providing full resources for hierarchical subselect clauses.
Metadata
Assignee
- International Business Machines Corporation
Inventors
- Shih-Gong Li
- Charles K. Bucher
- Kenneth R. Banning
Application Information
Application Number:US 7780486
Filing Date:1991-10-16
Priority Date:1991-10-16
Art Unit:236
Classifications
IPC:
G06F 3153G06F 1730
Field of Search:
395364500;600;157-161DIG. 1 MS File
Patent Drawings (41 sheets)
Description
Cross Reference to Related Applications
Subject matter in the present application is related to the invention in U.S. patent application Ser. No. 07/628,543 filed Dec. 17, 1990 under the title "Tree Structure Representation Of An SQL Clause".
Background of the Invention
The present invention relates generally to an interface between a human user and a computerized relational database. More particularly, the invention is directed to methods, systems and programs for comprehensively and bilaterally translating between structured query language (SQL) statements and graphically depicted queries as may be used to search a computer implemented relational database.
Relational form databases have become the subject of significant recent interest, not only because of the increasing volume of data being stored and retrieved by computerized databases but also by virtue of the data relationships which can be established during the storage and retrieval processes.
Structured query language (SQL), and in particular the ANSI SQL, has become the preferred language media for communicating queries to relational databases. As a consequence, there presently exist thousands of relational databases and thousands of related queries directed to such databases. Given the investment in such databases and queries, migration is not only a desirable feature, but a substantially necessary capability for new relational database systems and methods.
The concept of portraying a query in a visual depiction on the screen of a workstation is a relatively new approach to relational database interfacing. Visual queries, often referred to as graphical queries, utilize workstation graphics to represent the query objectives heretofore defined by SQL statements. The visual query presents in a pictorial depiction the objectives of the search, thereby eliminating the need for the user to learn SQL, improving the rate at which SQL queries can be formulated, and reducing the defect or error rate of queries. It is well recognized that SQL, though computationally efficient, is a difficult language for users to master and apply.
With the growing prevalence of relational databases, communication networks and workstations, the training and experience of a representative system user has decreased in relation to the resources available. The dilemma created by these various events is threefold. First, there exists an established and valuable base of queries formulated with classical SQL expressions. Second, there is a growing usage of relational databases and networks accessing their information. Finally, the end users of such databases are routinely less proficient in the very tools needed to efficiently and accurately access the relational database information. Thus, a distinct need exists for methods, systems and programs which convert SQL query statements into visual representations understandable by novice database users, and, in the compliment, which convert graphically or visually represented queries into SQL format statements usable in existing databases and network environments.
Summary of the Invention
The present invention provides a method, system and program for comprehensively and bilaterally translating between SQL query statements and equivalent visually or graphically depicted query representations. The two-way conversion is implemented using data structures. In the case of conversion between an SQL statement and the equivalent visual query, a parser divides the SQL statement and identifies the equivalent data structure. If desired, the parser can include resources to identify non-ANSI SQL statements, so that such unique elements of the SQL statement can be selectively translated by the user. Thus, in one aspect, the invention provides a means from migrating from the multitude of existing SQL formulated query statements to their graphic progeny.
The complementing translation, from a visual query to SQL equivalent, is preferably accomplished when the visual query is defined, by incrementally creating the data structure as the query is graphically formulated. The data structure is then used to generate the corresponding SQL query statement.
Translation between one data structure, such as the graphical query representation, and a second data structure, such as that associated with the SQL statement query, is accomplished thru a linking data structure. To accomplish this, the data structures are comprised of relational lists.
The graphical query is preferably formulated on a workstation. A representative workstation includes a windowing display suitable to depict individual SQL clauses in distinct windows. In this context, the user manipulates the arrangement of each clause within the context of a window and then links the clauses by window association. SQL query formulation is performed by conventional prompt line or through the practice of query by example formulations.
Bidirectional translation between an SQL or text formulated query statement and the equivalent visual or graphically depicted query provides a contemporary user with a broad base of resources. Preexisting SQL query statements can be graphically depicted for consideration and revision through a mere entry of the statement into the workstation. Thereby, the mysteries of existing SQL libraries are exposed to novice relational database users. On the other hand, such users are provided a visual context within which to formulate new queries, and to have such new queries converted to SQL statements directly applicable to a broad base of existing relational database systems.
These and other features of the invention will be more clearly understood and appreciated upon considering the detailed embodiment discussed hereinafter.
Brief Description of the Drawings
FIG. 1 schematically depicts a workstation connected to a network having a relational database.
FIG. 2 schematically illustrates a visual query screen, including windows suitable to define queries and a text based SQL equivalent.
FIGS. 3-7 schematically depict a set of common data structures for bidirectional translation.
FIGS. 8-27 schematically depict by flow diagram the steps for converting a visual query to a common data structure.
FIGS. 28-33 schematically depict by flow diagram the steps for converting a common data structure to a visual query.
FIGS. 34-42 schematically depict by flow diagram the steps for converting an SQL query statement to a common data structure.
FIG. 43 schematically depicts by flow diagram the steps for converting a common data structure to an SQL query statement with set operations.
FIGS. 44-48 schematically depict by flow diagram the steps for converting a common data structure to an SQL query statement without set operations.
Description of the Preferred Embodiment
Queries which seek to obtain information from relational databases are conventionally defined by ANSI standard structure query language (SQL) statements. These statements define in computer recognizable terms the tables from which the data is to be extracted, the columns of interest, the conditions rows must satisfy, what columns are to be included, how the select columns are to be grouped, the order of the columns, distinctiveness constraints in the columns, connections of data within tables, and lower level or subqueries to be integrated into the base queries. A simple text describing SQL and its uses is the IBM Operating Systems/2 Extended Edition Database Manager Structured Query Language (SQL) concepts booklet available from IBM Corporation. In addition to the ANSI standard SQL statements, there exist a number of nonstandard SQL statements within the relational database community. Thus, any bidirection translation resource must have the diversity of structure to interface a broad spectrum of relational database SQL language variances.
As noted earlier, comprehensive bidirectionality of the translation is important from the perspective of migrating from established SQL queries to their graphical or visual query equivalents. It is clearly inefficient to require the regeneration of existing SQL queries into the visual environment. At the same time, new visual queries should be available in SQL format for use on existing hardware with existing and relational databases. It is this comprehensive bidirectionality that is lacking in the prior art.
There presently do exist technologies which provide very limited translation from visual or graphical depictions of queries to their SQL equivalents. Representative examples are described in "Graphical User Languages for Querying Information: Where to look for criteria?" by Hrohr, as appeared in 1988 IEEE Workshop On Visual Languages, May, 1988, pages 14-20; "Design and Implementation of An Interactive Graphical Query Interface for a Relational Database Management System" by Czejdo et al, as appeared in 1988 IEEE Workshop On Visual Languages, May, 1988 pages 21-28; and "End-User Access to Relational Databases Metaphor Database Server" by Benjamin et al, as appeared in the summer 1987 issue of InfoDB. Unfortunately, the translations described in such publications were lacking both in comprehensive bidirectionality and scope of diversity. Namely, the focus was only directed toward translating from visual or graphical depictions to SQL. Furthermore, the translations were not ANSI standard SQL comprehensive, in that the row condition was incapable of handling diverse logical relationships, no mathematical relationships were permitted for column data, and, foremost, subquery handling was absent.
The article "User Interfaces for Structural Engineering Relational Database" by Howard et al as appeared in Engineering With Computers, 1988, pages 239-249, recognized the importance of bidirectional translation between a text based query, the defined Engineering Query Language and graphical representations. However the article did not disclose how such desirable objectives could be accomplished. The article recognized the potential need for translating relatively complex query formulations, but made no attempt to present a solution. In contrast, the present invention defines a method, system and program for accomplishing these desirable goals and doing so with the resources to handle complex formulations, including, but not limited to, the definition of complex logical and algebraic relationships between columns and the manipulation of hierarchical queries composed of subqueries.
The invention is preferably practiced in the context of a relational database such as is available in the OS/2 Extended Edition software program available from IBM Corporation. A representative hardware environment is depicted in FIG. 1, including an IBM brand PS/2 workstation, generally at 1, having resident thereon the OS/2 Standard Edition base operating system and the aforementioned OS/2 Extended Edition relational database program. Workstation 1 includes nonvolatile storage for the database, such as a hard disk, optical disk or tape drive media, and means for communicating into a network, generally at 2, having attached thereto further databases 3 and 4 as well as distinct non-proximate workstations such as 6. The fundamental goal is to provide a relatively unexperienced relational database user of workstation 1 with method, system and program resources to create, modify and execute relational database queries encompassing a broad and historical base of information. The invention further contemplates that preexisting queries formulated in classical SQL format be conveyed to workstation 1 and there subjected to conversion into visual or graphical queries equivalent for refinement or execution.
FIG. 2 illustrates a sample layout for a video display screen, such as screen 7 of workstation 1 in FIG. 1, to illustrate the content of a visually or graphically depicted query together with its SQL text equivalent. The SQL statement, generally in window 8, includes SELECT, FROM, WHERE, GROUP BY, HAVING and ORDER BY clauses, diverse logical relationships, mathematical relationships and subqueries. Note that most clauses and related tables are shown in independent windows. An example is the FROM clause in SQL window 8 which defines that the columns headed department (DEPT) and manager (MANAGER) are selected from independent tables respectively identified as staff (Staff) in window 9 and organization (ORG) in window 11. When new columns are defined in the SELECT clause, the columns are identified as being new by appropriate window. See window 12. A separate window also appears to identify that the GROUP BY clause relates a selected pair of columns from the potential sets defined by the interaction of the two tables. See window 13. Namely, columns DEPT and MANAGER are selected for grouping from the two tables Staff and ORG. Small window 14 is used to show that the distinct function has been disabled, thereby in conventional SQL methodology allowing redundancy in the rows selected for the response. No window is included to show that the answer has been defined to have an SQL ORDER BY requirement, namely, that the department listings be in ascending alphanumeric order.
The two windows at the bottom of the screen, 16 and 17, depict in graphical form the logical and mathematical relationships defined to satisfy the WHERE clause, a row condition, and the HAVING clause. The format of the Having Cond and Row Cond graphical depiction is the subject of the aforementioned copending patent application. With the preferred hardware and video display screen graphic environments defined, the ensuing description will focus on how one attains the desired method, system and program capabilities.
A central aspect of the invention was the recognition that bidirectional translation or conversion between text based SQL query statements and graphically based visual query representations requires the creation and use of a common data structure. As embodied, the common data structures is composed of multiple relatable lists. When the origin of the query is an SQL statement, the content of the lists for the common data structure is extracted by conventional parsing of the SQL statement. In the case a visual query, the data for the lists is captured and transformed into the common data structure during the graphical manipulation by the user.
The use of the common data structure provides a number of benefits. Paramount of those is the bidirectionality between the SQL query statement the visual representation of the query.
The common data structure described herein presumes an ANSI standard SQL language. However, and to the benefit of the user, the common data structure is amenable to additions as needed to cover SQL language variances. In part, this is attributable to the structured character of SQL, a language basically composed of distinguishable clauses.
For the preferred ANSI standard SQL embodiment described herein the data structures are composed of 8 elements. The composition of the structures as applied to the example query illustrated in FIG. 2 is depicted schematically by block diagram in FIG. 3. This SQL query establishes the following set of 8 basic data structures: (1) FromTable--an ordered list of tables from which data is to be queried, (2) SelectColumn--an ordered list of the column names which are included in the SelectClause, (3) SelectExp--an ordered list of expressions and column functions that are included in the SELECT clause, (4) WhereCond--the boolean expression in the WHERE clause, (5) GroupBy--an ordered list of column names which are in the GROUP BY clause, (6) HavingCond--the boolean expression in the HAVING clause, (7) OrderBy--the ordered list of (O.sub.-- ColumnName, OrderOp) where OrderOp defines either an ASC (ascending) or a DSC (descending) order of listing and O.sub.-- ColumnName is the column name specified in the Order By clause, and (8) DistinctFlag--the state of the DISTINCT key word.
To provide comprehensive bidirectionality between text format and visual representations of SQL queries, a preferred arrangement also includes an additional group of common data structures. The title of each such data structure, and its format, are set forth below.
(9) ColumnList--a data structure list for each table in the FromTable list. ColumnList contains a full list of the (ColumnName, Flag) data. The Flag data indicates if the ColumnName is selected for the SELECT clause. This list is readily constructed with system catalog information from the database management system.
(10) W.sub.-- JoinList--this data structure comprises a list of (LeftSide, RightSide) that stores the "LeftSide equal to RightSide" information, where both LeftSide and RightSide are columns belonging to tables listed in FromTable. Each entry in this list is considered a Join condition for the query and as such is not included in the WHERE condition window.
(11) W.sub.-- ParentChildren--this data structure is comprised of a list of (ParentNode, ChildrenNodes) where the ChildrenNodes are n-tuple consisting of the node names, which nodes are the children of the node specified in the ParentNode. For example, (N1, (N3, N4, N5)) represents that the node N3, N4 and N5 are the children nodes of node N1. This list is used for the WHERE condition.
(12) W.sub.-- NodeLocType--this is a list of (NodeName, Coordinates, Type), where Coordinates are the coordinates of NodeName relative to the bottom left corner of the WHERE condition window, and Type indicates that NodeName is a logical operator (AND or OR) node or a predicate.
(13) W.sub.-- PredicateData--this constitutes a list (NodeName, LeftSide, CompOp, ValueButton, RS.sub.-- Value, SubqueryButton, RS.sub.-- Subquery) which stores the information of the predicates in the WHERE condition. CompOp is the comparison operator. LeftSide is the expression left of the CompOp in the predicate. If ValueButton is in the ON state, the expression to the right of the CompOp in the predicate is merely a simple expression whose text is stored in RS.sub.-- Value list. If the SubqueryButton is ON, the right side is treated as another SELECT statement, thus considered a subquery to the SQL query statement. The subquery is represented by a query name stored in the RS.sub.-- Subquery list. The subquery is an individual query statement, in that it has its own data structure independent from the data structure query within which it resides.
(14) H.sub.-- ParentChildren--a list similar to that of the W.sub.-- ParentChildren, but for the HAVING condition.
(15) H.sub.-- NodeLocType,--this list is similar to the W.sub.-- NodeLocType but for the HAVING condition.
(16) H.sub.-- PredicateData, a list is similar to the W.sub.-- PredicateData, but for the HAVING condition.
(17) GroupList--a list of (ColumnName, GroupCheck) based upon the GroupBy structure. This list groups all the column names in ColumnList(I) for every Table(I) in the FromTable list. If a ColumnName entry also exists in the GroupBy list, the GroupCheck data is set ON. Otherwise, GroupCheck is set OFF.
(18) OrderList--this list is composed of (ColumnName, OrderOp, OrderNumber) and is based on the OrderBy structure. The list groups all the column names in ColumnList(I) from every Table(I) in the FromTable list. If a ColumnName entry also exists in the OrderBy list, the OrderNumber represents its position in the OrderBy list. Otherwise, the OrderNumber is left blank (null).
If the SQL language subject to bidirectional translation includes SET operations (UNION, INTERSECTION, EXCEPT), each query statement is treated as an individual query and a tree structure is used to represent the entire query. In the tree structure representation, the operator nodes are: UNION, UNION ALL, INTERSECT, INTERSECT ALL, EXCEPT, EXCEPT ALL, etc. In such a situation, the leaf nodes display the names for the query parts involved in the entire query. To implement this further SQL statement capability, three additional common data structures are needed.
(19) S.sub.-- ParentChildren--this is a list of (ParentNode, ChildrenNodes) in which the ChildrenNodes is an n-tuple consisting of the node names which are children of the node specified in the ParentNode. For example, (N1, (N3, N4, N5)) represents that node N3, N4 and N5 are ChildNodes of node N1. This list is used with all queries having a SET operation.
(20) S.sub.-- NodeLocType--this list is composed of (NodeName, Coordinates, Type) where Coordinates are the coordinates of NodeName relative to the bottom left corner of the query window, and Type indicates that NodeName is a SET operator (UNION, UNION ALL, INTERSECT, INTERSECT ALL, EXCEPT, EXCEPT ALL) node or a query.
(21) S.sub.-- NodeQuery--this is a list composed of (NodeName, QueryName) which links the query names with names of the nodes in the tree structure representation. Each query is regarded as an individual query with independent data structure.
The foregoing lists are the core group of common data structures needed to implement conventional SQL language queries in a comprehensive bidirectional translation environment. For special queries, non-ANSI standard types, minor variations in the parsing rules and information may have to be added. In those cases where the input has a previously generated SQL statement, a preferred arrangement of the present invention includes a resource to detect nonstandard statements during the parsing operation. Once intercepted, nonstandard SQL statements can be manually translated by the user or, if the frequency dictates, can be the subject to automatic translation using extensions of the data structures defined herein.
It should also be recognized that the present invention provides resources to generate common data structures for incomplete queries. The ability to translate in increments is particularly valuable from the perspective of tracking the evolution of a query in its SQL and visual counterparts.
FIGS. 4-6 depict the organization of the tables and lists corresponding to the common data structures ColumnList, W.sub.-- JoinList, W.sub.-- ParentChildren, W.sub.-- NodeLocType, W.sub.-- PredicateData, H.sub.-- ParentChildren, H.sub.-- NodeLocType, H.sub.-- PredicateData, GroupList and OrderList.
The data in the tables and lists of FIGS. 3-6 correspond to the information depicted in FIG. 2 by SQL statement and visual query equivalent.
FIG. 7 depicts the set of common data structures needed to implement the SET operations. Since the query example depicted in FIG. 2 does not include any SET relationships, the data in the tables is set to NULL.
Pseudocode, from which source code and related object code can be derived, suitable to practice the presently disclosed system, method and program is set forth in the ensuing text. The first block of pseudocode relates to the building of a common data structure from a visual query interface, as identified by heading comment. The corresponding set of flow diagrams for the translation between a visual query and the common data structure appears in the succession of FIGS. 8-27.
Pseudocode suitable to define the translation between the common data structure and the visual query equivalent is set forth below. The corresponding flow diagrams to practice such-operations are set forth in the succession of FIGS. 28-33.
Pseudocode for deriving the translation between an SQL query statement and the common data structure is set forth below and presented by a flow diagram in the succession of FIGS. 34-42.
Pseudocode for translating back from the common data structure to the SQL query statement with SET operations is set forth in the ensuing code and presented by flow diagram in FIG. 43.
Pseudocode suitable to translate from the common data structure to an SQL query without the SET operations is set forth below. The corresponding flow diagrams are schematically depicted in this succession of FIGS. 44-48.
The creation of a Boolean factor tree as described in the flow diagrams of FIGS. 35, 38 and 41, is preferably accomplished by following the procedures described in the aforementioned article entitled, "Method of Detecting Atomic Boolean Factors", as appeared on pages 368-374 of the IBM Technical Disclosure Bulletin, Vol. 32, No. 5B, October, 1989. Other methods of parsing the SQL statement to create Boolean factor trees are also known and equally viable to accomplish these increments in the flow of the operation for translating an SQL statement into a common data structure.
Particular relevance should be given to the fact that the present apparatus, method and program for converting is both bidirectional and comprehensive. The bidirectionality is particularly important from the perspective of migrating libraries of existing SQL queries. The comprehensiveness eases such migration through the ability to handle diverse logical and mathematical relationships in the clauses, such as the WHERE clause, together with the ability to fully handle subqueries. The implications of subqueries were a particular problem for previously known approaches. The ability to translate from SQL to visual representation is distinctly unique, combining the parsing of SQL clauses, the translation into a common date structure, and the eventual translation into both graphical blocks and the links relating the windowed data.
The visual representation of a query by windows, as set forth in FIG. 2, is preferred from the perspective of user friendliness. In a preferred context, a window is allocated for each table in the FROM statement, and contains therein a list of the column names. The columns names subject to the SELECT statement are highlighted in the table windows. A NewColumn window is used to identify user defined expressions in the SELECT clause. WHERE clauses for relating predicates joined by AND and OR logic are shown by tree representation in separate windows, such as the depicted Row Cond window. GROUP BY statements are shown in a separate window, with the selected columns identified. A HAVING condition window, such as appears in FIG. 2, also contains a tree representation of the statement logic. An ORDER BY clause could also be added as a separate window to search the prescribed order. Window graphics to show whether the DISTINCT clause is ON or OFF are also depicted in FIG. 2.
A subselect in a query can be displayed by name or icon as an element of a row condition predicate. Upon selection, the subquery would have its own primary window and associated clause windows in a direct graphical hierarchy. SET operations can be shown by individual objects in the query, including graphically depicted links between windows.
Though the invention has been described and illustrated by way of a specific embodiment, the methods, systems and programs encompassed by the invention should be interpreted consistent with the breadth of the claims set forth hereinafter.
Claims
What is claimed is:
1. A method for operating a database in a computer system to bidirectionally translate between graphical and text format representations of a database query, comprising the steps of: generating in the system a first data structure including a first link, which first data structure relates to a graphical format query; generating in the system a second data structure including a second link, which second data structure relates to a text format query; and bidirectionally translating between graphical format and text format queries using the first and second links.
2. The method recited in claim 1, wherein the bidirectional translation is accomplished so that the graphical and the text formats are functionally equivalent queries.
3. The method recited in claim 2, wherein the data structures are comprised of relational lists.
4. The method recited in claim 3, wherein the data structures define Boolean operators.
5. The method recited in claim 4, wherein the database is relational and the text format query uses a structured query language.
6. The method recited in claim 5, wherein the graphical format query is depicted on a video display screen using windows for one or more query clause relationships.
7. The method recited in claim 5, wherein one or more clauses of the database query uses a WHERE or HAVING clause.
8. The method recited in claim 6, wherein one or more clauses of the database query uses a WHERE or HAVING clause.
9. A computer system for bidirectionally translating between graphical and text format representations of a database query, comprising: a video display for depicting a database query in graphical or text formats; means for a user of the system to define a database query expression in graphical or text format through a physical interaction between the user and the system; means for creating a first data structure, including a first link, which relates to a graphical format query, responsive to the means for a user of the system to define; means for creating a second data structure, including a second link, which relates to a text format query, responsive to the means for a user of the system to define; means for bidirectionally translating between graphical format and text format queries using the first and second links; and means for the video display to depict the database query defined by the user in a user selected format.
10. The system recited in claim 9, wherein the means for bidirectionally translating provides that the graphical and the text formats are functionally equivalent queries.
11. The system recited in claim 10, wherein the database is relational and the text format query uses structured query language.
12. The system recited in claim 11, wherein the graphical format query uses windows to depict one or more query clause relationships on the video display.
13. The system recited in claim 11, wherein one or more clauses in the database query uses a WHERE or HAVING clause.
14. The system recited in claim 12, wherein one or more clauses in the database query uses a WHERE or HAVING clause.
Patent Citations (2)
Non-Patent Literature (5)
- Database Manager Structured Query Language (SQL) Concepts IBM Copyright 1988, 1990.
- Graphical User Languages For Querying Information: Where To Look For Criteria?, Gabriele Rohr, 1988IEEE, pp. 21-28.
- Design and Implementation of an Interactive Graphical Query Interface for a Relational Database, Bogdan Czejdo, Venugopal Reddy, Marek Rusinkiewicz, 1988 IEEE, pp. 14-20.
- End-User Access to Relational Databases Metaphor Database Server, Art Benjamin and David Rossetti, 1987.
- Engineering with Computers, User Interfaces for Structural Engineering Relational Data Base, H. Craig Howard and Cynthia Stotts Howard, 1988.