| --- |
| layout: docpage |
| |
| title: "Documentation" |
| |
| is_homepage: false |
| is_sphinx_doc: true |
| |
| doc-parent: "Data Modeling" |
| |
| doc-title: "Defining Application Queries" |
| doc-header-links: ' |
| <link rel="top" title="Apache Cassandra Documentation v4.0-beta4" href="../index.html"/> |
| <link rel="up" title="Data Modeling" href="index.html"/> |
| <link rel="next" title="Logical Data Modeling" href="data_modeling_logical.html"/> |
| <link rel="prev" title="RDBMS Design" href="data_modeling_rdbms.html"/> |
| ' |
| doc-search-path: "../search.html" |
| |
| extra-footer: ' |
| <script type="text/javascript"> |
| var DOCUMENTATION_OPTIONS = { |
| URL_ROOT: "", |
| VERSION: "", |
| COLLAPSE_INDEX: false, |
| FILE_SUFFIX: ".html", |
| HAS_SOURCE: false, |
| SOURCELINK_SUFFIX: ".txt" |
| }; |
| </script> |
| ' |
| |
| --- |
| <div class="container-fluid"> |
| <div class="row"> |
| <div class="col-md-3"> |
| <div class="doc-navigation"> |
| <div class="doc-menu" role="navigation"> |
| <div class="navbar-header"> |
| <button type="button" class="pull-left navbar-toggle" data-toggle="collapse" data-target=".sidebar-navbar-collapse"> |
| <span class="sr-only">Toggle navigation</span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| </button> |
| </div> |
| <div class="navbar-collapse collapse sidebar-navbar-collapse"> |
| <form id="doc-search-form" class="navbar-form" action="../search.html" method="get" role="search"> |
| <div class="form-group"> |
| <input type="text" size="30" class="form-control input-sm" name="q" placeholder="Search docs"> |
| <input type="hidden" name="check_keywords" value="yes" /> |
| <input type="hidden" name="area" value="default" /> |
| </div> |
| </form> |
| |
| |
| |
| <ul class="current"> |
| <li class="toctree-l1"><a class="reference internal" href="../getting_started/index.html">Getting Started</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../new/index.html">New Features in Apache Cassandra 4.0</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../architecture/index.html">Architecture</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../cql/index.html">The Cassandra Query Language (CQL)</a></li> |
| <li class="toctree-l1 current"><a class="reference internal" href="index.html">Data Modeling</a><ul class="current"> |
| <li class="toctree-l2"><a class="reference internal" href="intro.html">Introduction</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="data_modeling_conceptual.html">Conceptual Data Modeling</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="data_modeling_rdbms.html">RDBMS Design</a></li> |
| <li class="toctree-l2 current"><a class="current reference internal" href="#">Defining Application Queries</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="data_modeling_logical.html">Logical Data Modeling</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="data_modeling_physical.html">Physical Data Modeling</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="data_modeling_refining.html">Evaluating and Refining Data Models</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="data_modeling_schema.html">Defining Database Schema</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="data_modeling_tools.html">Cassandra Data Modeling Tools</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l1"><a class="reference internal" href="../configuration/index.html">Configuring Cassandra</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../operating/index.html">Operating Cassandra</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../tools/index.html">Cassandra Tools</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../troubleshooting/index.html">Troubleshooting</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../development/index.html">Contributing to Cassandra</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../faq/index.html">Frequently Asked Questions</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../plugins/index.html">Third-Party Plugins</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../bugs.html">Reporting Bugs</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../contactus.html">Contact us</a></li> |
| </ul> |
| |
| |
| |
| </div><!--/.nav-collapse --> |
| </div> |
| </div> |
| </div> |
| <div class="col-md-8"> |
| <div class="content doc-content"> |
| <div class="content-container"> |
| |
| <div class="section" id="defining-application-queries"> |
| <h1>Defining Application Queries<a class="headerlink" href="#defining-application-queries" title="Permalink to this headline">¶</a></h1> |
| <p>Let’s try the query-first approach to start designing the data model for |
| a hotel application. The user interface design for the application is |
| often a great artifact to use to begin identifying queries. Let’s assume |
| that you’ve talked with the project stakeholders and your UX designers |
| have produced user interface designs or wireframes for the key use |
| cases. You’ll likely have a list of shopping queries like the following:</p> |
| <ul class="simple"> |
| <li>Q1. Find hotels near a given point of interest.</li> |
| <li>Q2. Find information about a given hotel, such as its name and |
| location.</li> |
| <li>Q3. Find points of interest near a given hotel.</li> |
| <li>Q4. Find an available room in a given date range.</li> |
| <li>Q5. Find the rate and amenities for a room.</li> |
| </ul> |
| <p>It is often helpful to be able to refer |
| to queries by a shorthand number rather that explaining them in full. |
| The queries listed here are numbered Q1, Q2, and so on, which is how they |
| are referenced in diagrams throughout the example.</p> |
| <p>Now if the application is to be a success, you’ll certainly want |
| customers to be able to book reservations at hotels. This includes |
| steps such as selecting an available room and entering their guest |
| information. So clearly you will also need some queries that address the |
| reservation and guest entities from the conceptual data model. Even |
| here, however, you’ll want to think not only from the customer |
| perspective in terms of how the data is written, but also in terms of |
| how the data will be queried by downstream use cases.</p> |
| <p>You natural tendency as might be to focus first on |
| designing the tables to store reservation and guest records, and only |
| then start thinking about the queries that would access them. You may |
| have felt a similar tension already when discussing the |
| shopping queries before, thinking “but where did the hotel and point of |
| interest data come from?” Don’t worry, you will see soon enough. |
| Here are some queries that describe how users will access |
| reservations:</p> |
| <ul class="simple"> |
| <li>Q6. Lookup a reservation by confirmation number.</li> |
| <li>Q7. Lookup a reservation by hotel, date, and guest name.</li> |
| <li>Q8. Lookup all reservations by guest name.</li> |
| <li>Q9. View guest details.</li> |
| </ul> |
| <p>All of the queries are shown in the context of the workflow of the |
| application in the figure below. Each box on the diagram represents a |
| step in the application workflow, with arrows indicating the flows |
| between steps and the associated query. If you’ve modeled the application |
| well, each step of the workflow accomplishes a task that “unlocks” |
| subsequent steps. For example, the “View hotels near POI” task helps |
| the application learn about several hotels, including their unique keys. |
| The key for a selected hotel may be used as part of Q2, in order to |
| obtain detailed description of the hotel. The act of booking a room |
| creates a reservation record that may be accessed by the guest and |
| hotel staff at a later time through various additional queries.</p> |
| <img alt="../_images/data_modeling_hotel_queries.png" src="../_images/data_modeling_hotel_queries.png" /> |
| <p><em>Material adapted from Cassandra, The Definitive Guide. Published by |
| O’Reilly Media, Inc. Copyright © 2020 Jeff Carpenter, Eben Hewitt. |
| All rights reserved. Used with permission.</em></p> |
| </div> |
| |
| |
| |
| |
| <div class="doc-prev-next-links" role="navigation" aria-label="footer navigation"> |
| |
| <a href="data_modeling_logical.html" class="btn btn-default pull-right " role="button" title="Logical Data Modeling" accesskey="n">Next <span class="glyphicon glyphicon-circle-arrow-right" aria-hidden="true"></span></a> |
| |
| |
| <a href="data_modeling_rdbms.html" class="btn btn-default" role="button" title="RDBMS Design" accesskey="p"><span class="glyphicon glyphicon-circle-arrow-left" aria-hidden="true"></span> Previous</a> |
| |
| </div> |
| |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |