<!DOCTYPE html>
<html lang="en-US">

  <head>
    <meta charset='utf-8'>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,maximum-scale=2">
    <link rel="stylesheet" href="assets/css/style.css?v=">
    <script src="https://code.jquery.com/jquery-3.3.0.min.js" integrity="sha256-RTQy8VOmNlT6b2PIRur37p6JEBZUE7o8wPgMvu18MC4=" crossorigin="anonymous"></script>
    <script src="assets/js/main.js"></script>
<!-- Begin Jekyll SEO tag v2.6.1 -->
<title>BIRDS | Bidirectional Transformation for Relational View Update Datalog-based Strategies</title>
<meta name="generator" content="Jekyll v4.0.0" />
<meta property="og:title" content="BIRDS" />
<meta property="og:locale" content="en_US" />
<meta name="description" content="Bidirectional Transformation for Relational View Update Datalog-based Strategies" />
<meta property="og:description" content="Bidirectional Transformation for Relational View Update Datalog-based Strategies" />
<meta property="og:site_name" content="BIRDS" />
<script type="application/ld+json">
{"@type":"WebPage","url":"/music-tutorial.html","headline":"BIRDS","description":"Bidirectional Transformation for Relational View Update Datalog-based Strategies","@context":"https://schema.org"}</script>
<!-- End Jekyll SEO tag -->

  </head>

  <body>

    <!-- HEADER -->
    <div id="header_wrap" class="outer">
        <header class="inner">
          
            <a id="forkme_banner" href="https://github.com/dangtv/BIRDS">View on GitHub</a>
          
          <a id="project_title" href="/BIRDS">BIRDS</a>
           <!-- <h1 id="project_title">  BIRDS </h1>  -->
          <h2 id="project_tagline">Bidirectional Transformation for Relational View Update Datalog-based Strategies</h2>

          
        </header>
    </div>

    <!-- MAIN CONTENT -->
    <div id="main_content_wrap" class="outer, wrapper">
      <div class="inner">
          <nav>
              <h3>Contents</h3>
              <ul></ul>
            </nav>
        <section id="main_content">
          <h1 id="example-music-schema">Example: music schema</h1>

<p>The music schema (<a href="https://github.com/dangtv/BIRDS/tree/master/examples/music/schema.sql">schema.sql</a>) is from an example in the paper “<a href="https://dl.acm.org/citation.cfm?id=1142399">Relational lenses: a language for updatable views</a>”</p>

<p>tracks1</p>

<table>
  <thead>
    <tr>
      <th>track</th>
      <th>date</th>
      <th>rating</th>
      <th>album</th>
      <th>quantity</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Trust</td>
      <td>2018</td>
      <td>5</td>
      <td>Wish</td>
      <td>5</td>
    </tr>
    <tr>
      <td>Lovesong</td>
      <td>2018</td>
      <td>5</td>
      <td>Galore</td>
      <td>1</td>
    </tr>
    <tr>
      <td>Mysong</td>
      <td>2018</td>
      <td>5</td>
      <td>Galore</td>
      <td>1</td>
    </tr>
    <tr>
      <td>Lullaby</td>
      <td>2018</td>
      <td>3</td>
      <td>Show</td>
      <td>3</td>
    </tr>
  </tbody>
</table>

<h2 id="an-update-strategy-for-tracks2">An update strategy for <code class="highlighter-rouge">tracks2</code></h2>

<p>An update strategy on the view <code class="highlighter-rouge">tracks2</code> by using Datalog (<a href="https://github.com/dangtv/BIRDS/tree/master/examples/music/tracks2.dl">tracks2.dl</a>):</p>

<div class="language-prolog highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">% describe the schema of sources and views</span>
<span class="ss">source</span> <span class="ss">tracks1</span><span class="p">(</span><span class="ss">'TRACK'</span><span class="o">:</span><span class="ss">string</span><span class="p">,</span><span class="ss">'DATE'</span><span class="o">:</span><span class="ss">int</span><span class="p">,</span><span class="ss">'RATING'</span><span class="o">:</span><span class="ss">int</span><span class="p">,</span><span class="ss">'ALBUM'</span><span class="o">:</span><span class="ss">string</span><span class="p">,</span><span class="ss">'QUANTITY'</span><span class="o">:</span><span class="ss">int</span><span class="p">).</span>
<span class="ss">view</span> <span class="ss">tracks2</span><span class="p">(</span><span class="ss">'TRACK'</span><span class="o">:</span><span class="ss">string</span><span class="p">,</span><span class="ss">'RATING'</span><span class="o">:</span><span class="ss">int</span><span class="p">,</span><span class="ss">'ALBUM'</span><span class="o">:</span><span class="ss">string</span><span class="p">,</span><span class="ss">'QUANTITY'</span><span class="o">:</span><span class="ss">int</span><span class="p">).</span>

<span class="c1">% rule for deletion from tracks1</span>
<span class="o">-</span><span class="ss">tracks1</span><span class="p">(</span><span class="nv">TRACK</span><span class="p">,</span><span class="nv">DATE</span><span class="p">,</span><span class="nv">RATING</span><span class="p">,</span><span class="nv">ALBUM</span><span class="p">,</span><span class="nv">QUANTITY</span><span class="p">)</span> <span class="p">:-</span> <span class="ss">tracks1</span><span class="p">(</span><span class="nv">TRACK</span><span class="p">,</span><span class="nv">DATE</span><span class="p">,</span><span class="nv">RATING</span><span class="p">,</span><span class="nv">ALBUM</span><span class="p">,</span><span class="nv">QUANTITY</span><span class="p">),</span>
    <span class="ss">not</span> <span class="ss">tracks2</span><span class="p">(</span><span class="nv">TRACK</span><span class="p">,</span><span class="nv">RATING</span><span class="p">,</span><span class="nv">ALBUM</span><span class="p">,</span><span class="nv">QUANTITY</span><span class="p">).</span>

<span class="o">+</span><span class="ss">tracks1</span><span class="p">(</span><span class="nv">TRACK</span><span class="p">,</span><span class="nv">DATE</span><span class="p">,</span><span class="nv">RATING</span><span class="p">,</span><span class="nv">ALBUM</span><span class="p">,</span><span class="nv">QUANTITY</span><span class="p">)</span> <span class="p">:-</span> <span class="ss">tracks2</span><span class="p">(</span><span class="nv">TRACK</span><span class="p">,</span><span class="nv">RATING</span><span class="p">,</span><span class="nv">ALBUM</span><span class="p">,</span><span class="nv">QUANTITY</span><span class="p">),</span>
    <span class="ss">not</span> <span class="ss">tracks1</span><span class="p">(</span><span class="nv">TRACK</span><span class="p">,</span><span class="nv">_</span><span class="p">,</span><span class="nv">RATING</span><span class="p">,</span><span class="nv">ALBUM</span><span class="p">,</span><span class="nv">QUANTITY</span><span class="p">),</span> <span class="ss">tracks1</span><span class="p">(</span><span class="nv">TRACK</span><span class="p">,</span><span class="nv">DATE</span><span class="p">,</span><span class="nv">_</span><span class="p">,</span><span class="nv">ALBUM</span><span class="p">,</span><span class="nv">_</span><span class="p">).</span>

<span class="o">+</span><span class="ss">tracks1</span><span class="p">(</span><span class="nv">TRACK</span><span class="p">,</span><span class="m">2018</span><span class="p">,</span><span class="nv">RATING</span><span class="p">,</span><span class="nv">ALBUM</span><span class="p">,</span><span class="nv">QUANTITY</span><span class="p">)</span> <span class="p">:-</span> <span class="ss">tracks2</span><span class="p">(</span><span class="nv">TRACK</span><span class="p">,</span><span class="nv">RATING</span><span class="p">,</span><span class="nv">ALBUM</span><span class="p">,</span><span class="nv">QUANTITY</span><span class="p">),</span>
    <span class="ss">not</span> <span class="ss">tracks1</span><span class="p">(</span><span class="nv">TRACK</span><span class="p">,</span><span class="nv">_</span><span class="p">,</span><span class="nv">_</span><span class="p">,</span><span class="nv">ALBUM</span><span class="p">,</span><span class="nv">_</span><span class="p">).</span>
</code></pre></div></div>

<p>Verifying and compiling the update strategy into SQL statements saved in the file (<a href="https://github.com/dangtv/BIRDS/tree/master/examples/music/tracks2.sql">tracks2.sql</a>):</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>birds <span class="nt">-v</span> <span class="nt">-f</span> tracks2.dl <span class="nt">-o</span> tracks2.sql
</code></pre></div></div>

<h2 id="an-update-strategy-for-tracks3">An update strategy for <code class="highlighter-rouge">tracks3</code></h2>

<p>An update strategy on the view <code class="highlighter-rouge">tracks3</code> over the view <code class="highlighter-rouge">tracks2</code> by using Datalog (<a href="https://github.com/dangtv/BIRDS/tree/master/examples/music/tracks3.dl">tracks3.dl</a>):</p>

<div class="language-prolog highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">% describe the schema of sources and views</span>
<span class="ss">source</span> <span class="ss">tracks2</span><span class="p">(</span><span class="ss">'TRACK'</span><span class="o">:</span><span class="ss">string</span><span class="p">,</span><span class="ss">'RATING'</span><span class="o">:</span><span class="ss">int</span><span class="p">,</span><span class="ss">'ALBUM'</span><span class="o">:</span><span class="ss">string</span><span class="p">,</span><span class="ss">'QUANTITY'</span><span class="o">:</span><span class="ss">int</span><span class="p">).</span>
<span class="ss">view</span> <span class="ss">tracks3</span><span class="p">(</span><span class="ss">'TRACK'</span><span class="o">:</span><span class="ss">string</span><span class="p">,</span><span class="ss">'RATING'</span><span class="o">:</span><span class="ss">int</span><span class="p">,</span><span class="ss">'ALBUM'</span><span class="o">:</span><span class="ss">string</span><span class="p">,</span><span class="ss">'QUANTITY'</span><span class="o">:</span><span class="ss">int</span><span class="p">).</span>

<span class="c1">% constraints:</span>
<span class="err">⊥</span><span class="p">()</span> <span class="p">:-</span> <span class="ss">tracks3</span><span class="p">(</span><span class="nv">T</span><span class="p">,</span><span class="nv">R</span><span class="p">,</span><span class="nv">A</span><span class="p">,</span><span class="nv">Q</span><span class="p">),</span> <span class="nv">NOT</span> <span class="nv">Q</span><span class="o">&gt;</span><span class="m">2</span><span class="p">.</span>

<span class="c1">% view definition:</span>
<span class="c1">% tracks3(T,R,A,Q) :- tracks2(T,R,A,Q),Q &gt; 2.</span>

<span class="c1">% rule for insertion to tracks2</span>
<span class="o">+</span><span class="ss">tracks2</span><span class="p">(</span><span class="nv">TRACK</span><span class="p">,</span><span class="nv">RATING</span><span class="p">,</span><span class="nv">ALBUM</span><span class="p">,</span><span class="nv">QUANTITY</span><span class="p">)</span> <span class="p">:-</span> <span class="ss">tracks3</span><span class="p">(</span><span class="nv">TRACK</span><span class="p">,</span><span class="nv">RATING</span><span class="p">,</span><span class="nv">ALBUM</span><span class="p">,</span><span class="nv">QUANTITY</span><span class="p">),</span>
    <span class="ss">not</span> <span class="ss">tracks2</span><span class="p">(</span><span class="nv">TRACK</span><span class="p">,</span><span class="nv">RATING</span><span class="p">,</span><span class="nv">ALBUM</span><span class="p">,</span><span class="nv">QUANTITY</span><span class="p">),</span> <span class="nv">QUANTITY</span> <span class="o">&gt;</span> <span class="m">2</span><span class="p">.</span>

<span class="c1">% rule for deletion from tracks2</span>
<span class="o">-</span><span class="ss">tracks2</span><span class="p">(</span><span class="nv">TRACK</span><span class="p">,</span><span class="nv">RATING</span><span class="p">,</span><span class="nv">ALBUM</span><span class="p">,</span><span class="nv">QUANTITY</span><span class="p">)</span> <span class="p">:-</span> <span class="ss">tracks2</span><span class="p">(</span><span class="nv">TRACK</span><span class="p">,</span><span class="nv">RATING</span><span class="p">,</span><span class="nv">ALBUM</span><span class="p">,</span><span class="nv">QUANTITY</span><span class="p">),</span>
    <span class="ss">not</span> <span class="ss">tracks3</span><span class="p">(</span><span class="nv">TRACK</span><span class="p">,</span><span class="nv">RATING</span><span class="p">,</span><span class="nv">ALBUM</span><span class="p">,</span><span class="nv">QUANTITY</span><span class="p">),</span> <span class="nv">QUANTITY</span> <span class="o">&gt;</span> <span class="m">2</span><span class="p">.</span>
</code></pre></div></div>

<p>Verifying and compiling the update strategy to SQL statements saved in the file (<a href="https://github.com/dangtv/BIRDS/tree/master/examples/music/tracks3.sql">tracks3.sql</a>):</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>birds <span class="nt">-v</span> <span class="nt">-f</span> tracks3.dl <span class="nt">-o</span> tracks3.sql
</code></pre></div></div>

        </section>
      </div>
    </div>
    
    <!-- FOOTER  -->
    <div id="footer_wrap" class="outer">
      <footer class="inner">
        <p style="margin-bottom:0em"><small>
          
          Maintained by <a href="https://dangtv.github.io">Vandang Tran</a>, Hiroyuki Kato, Zhenjiang Hu</small>.
        
        <small>Theme based on <a href="https://github.com/pages-themes/slate">Slate</a></small>.
        <small>Last updated on 2 Dec 2020</small></p>
      </footer>
    </div>

    
  </body>
</html>