blob: b74df091d000bfb8f589868320457dd4be5726c1 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Apache Flink: Sharing is caring - Catalogs in Flink SQL</title>
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<!-- Bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/flink.css">
<link rel="stylesheet" href="/css/syntax.css">
<!-- Blog RSS feed -->
<link href="/blog/feed.xml" rel="alternate" type="application/rss+xml" title="Apache Flink Blog: RSS feed" />
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<!-- We need to load Jquery in the header for custom google analytics event tracking-->
<script src="/js/jquery.min.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- Main content. -->
<div class="container">
<div class="row">
<div id="sidebar" class="col-sm-3">
<!-- Top navbar. -->
<nav class="navbar navbar-default">
<!-- The logo. -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="navbar-logo">
<a href="/">
<img alt="Apache Flink" src="/img/flink-header-logo.svg" width="147px" height="73px">
</a>
</div>
</div><!-- /.navbar-header -->
<!-- The navigation links. -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-main">
<!-- First menu section explains visitors what Flink is -->
<!-- What is Stream Processing? -->
<!--
<li><a href="/streamprocessing1.html">What is Stream Processing?</a></li>
-->
<!-- What is Flink? -->
<li><a href="/flink-architecture.html">What is Apache Flink?</a></li>
<!-- What is Stateful Functions? -->
<li><a href="/stateful-functions.html">What is Stateful Functions?</a></li>
<!-- Use cases -->
<li><a href="/usecases.html">Use Cases</a></li>
<!-- Powered by -->
<li><a href="/poweredby.html">Powered By</a></li>
&nbsp;
<!-- Second menu section aims to support Flink users -->
<!-- Downloads -->
<li><a href="/downloads.html">Downloads</a></li>
<!-- Getting Started -->
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Getting Started<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="https://ci.apache.org/projects/flink/flink-docs-release-1.11/getting-started/index.html" target="_blank">With Flink <small><span class="glyphicon glyphicon-new-window"></span></small></a></li>
<li><a href="https://ci.apache.org/projects/flink/flink-statefun-docs-release-2.1/getting-started/project-setup.html" target="_blank">With Flink Stateful Functions <small><span class="glyphicon glyphicon-new-window"></span></small></a></li>
<li><a href="/training.html">Training Course</a></li>
</ul>
</li>
<!-- Documentation -->
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Documentation<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="https://ci.apache.org/projects/flink/flink-docs-release-1.11" target="_blank">Flink 1.11 (Latest stable release) <small><span class="glyphicon glyphicon-new-window"></span></small></a></li>
<li><a href="https://ci.apache.org/projects/flink/flink-docs-master" target="_blank">Flink Master (Latest Snapshot) <small><span class="glyphicon glyphicon-new-window"></span></small></a></li>
<li><a href="https://ci.apache.org/projects/flink/flink-statefun-docs-release-2.1" target="_blank">Flink Stateful Functions 2.1 (Latest stable release) <small><span class="glyphicon glyphicon-new-window"></span></small></a></li>
<li><a href="https://ci.apache.org/projects/flink/flink-statefun-docs-master" target="_blank">Flink Stateful Functions Master (Latest Snapshot) <small><span class="glyphicon glyphicon-new-window"></span></small></a></li>
</ul>
</li>
<!-- getting help -->
<li><a href="/gettinghelp.html">Getting Help</a></li>
<!-- Blog -->
<li><a href="/blog/"><b>Flink Blog</b></a></li>
<!-- Flink-packages -->
<li>
<a href="https://flink-packages.org" target="_blank">flink-packages.org <small><span class="glyphicon glyphicon-new-window"></span></small></a>
</li>
&nbsp;
<!-- Third menu section aim to support community and contributors -->
<!-- Community -->
<li><a href="/community.html">Community &amp; Project Info</a></li>
<!-- Roadmap -->
<li><a href="/roadmap.html">Roadmap</a></li>
<!-- Contribute -->
<li><a href="/contributing/how-to-contribute.html">How to Contribute</a></li>
<!-- GitHub -->
<li>
<a href="https://github.com/apache/flink" target="_blank">Flink on GitHub <small><span class="glyphicon glyphicon-new-window"></span></small></a>
</li>
&nbsp;
<!-- Language Switcher -->
<li>
<a href="/zh/2020/07/23/catalogs.html">中文版</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-bottom">
<hr />
<!-- Twitter -->
<li><a href="https://twitter.com/apacheflink" target="_blank">@ApacheFlink <small><span class="glyphicon glyphicon-new-window"></span></small></a></li>
<!-- Visualizer -->
<li class=" hidden-md hidden-sm"><a href="/visualizer/" target="_blank">Plan Visualizer <small><span class="glyphicon glyphicon-new-window"></span></small></a></li>
<hr />
<li><a href="https://apache.org" target="_blank">Apache Software Foundation <small><span class="glyphicon glyphicon-new-window"></span></small></a></li>
<li>
<style>
.smalllinks:link {
display: inline-block !important; background: none; padding-top: 0px; padding-bottom: 0px; padding-right: 0px; min-width: 75px;
}
</style>
<a class="smalllinks" href="https://www.apache.org/licenses/" target="_blank">License</a> <small><span class="glyphicon glyphicon-new-window"></span></small>
<a class="smalllinks" href="https://www.apache.org/security/" target="_blank">Security</a> <small><span class="glyphicon glyphicon-new-window"></span></small>
<a class="smalllinks" href="https://www.apache.org/foundation/sponsorship.html" target="_blank">Donate</a> <small><span class="glyphicon glyphicon-new-window"></span></small>
<a class="smalllinks" href="https://www.apache.org/foundation/thanks.html" target="_blank">Thanks</a> <small><span class="glyphicon glyphicon-new-window"></span></small>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
</div>
<div class="col-sm-9">
<div class="row-fluid">
<div class="col-sm-12">
<div class="row">
<h1>Sharing is caring - Catalogs in Flink SQL</h1>
<p><i></i></p>
<article>
<p>23 Jul 2020 Dawid Wysakowicz (<a href="https://twitter.com/dwysakowicz">@dwysakowicz</a>)</p>
<p>With an ever-growing number of people working with data, it’s a common practice for companies to build self-service platforms with the goal of democratizing their access across different teams and — especially — to enable users from any background to be independent in their data needs. In such environments, metadata management becomes a crucial aspect. Without it, users often work blindly, spending too much time searching for datasets and their location, figuring out data formats and similar cumbersome tasks.</p>
<p>In this blog post, we want to give you a high level overview of catalogs in Flink. We’ll describe why you should consider using them and what you can achieve with one in place. To round it up, we’ll also showcase how simple it is to combine catalogs and Flink, in the form of an end-to-end example that you can try out yourself.</p>
<h2 id="why-do-i-need-a-catalog">Why do I need a catalog?</h2>
<p>Frequently, companies start building a data platform with a metastore, catalog, or schema registry of some sort already in place. Those let you clearly separate making the data available from consuming it. That separation has a few benefits:</p>
<ul>
<li><strong>Improved productivity</strong> - The most obvious one. Making data reusable and shifting the focus on building new models/pipelines rather than data cleansing and discovery.</li>
<li><strong>Security</strong> - You can control the access to certain features of the data. For example, you can make the schema of the dataset publicly available, but limit the actual access to the underlying data only to particular teams.</li>
<li><strong>Compliance</strong> - If you have all the metadata in a central entity, it’s much easier to ensure compliance with GDPR and similar regulations and legal requirements.</li>
</ul>
<h2 id="what-is-stored-in-a-catalog">What is stored in a catalog?</h2>
<p>Almost all data sets can be described by certain properties that must be known in order to consume them. Those include:</p>
<ul>
<li>
<p><strong>Schema</strong> - It describes the actual contents of the data, what columns it has, what are the constraints (e.g. keys) on which the updates should be performed, which fields can act as time attributes, what are the rules for watermark generation and so on.</p>
</li>
<li>
<p><strong>Location</strong> - Does the data come from Kafka or a file in a filesystem? How do you connect to the external system? Which topic or file name do you use?</p>
</li>
<li>
<p><strong>Format</strong> - Is the data serialized as JSON, CSV, or maybe Avro records?</p>
</li>
<li>
<p><strong>Statistics</strong> - You can also store additional information that can be useful when creating an execution plan of your query. For example, you can choose the best join algorithm, based on the number of rows in joined datasets.</p>
</li>
</ul>
<p>Catalogs don’t have to be limited to the metadata of datasets. You can usually store other objects that can be reused in different scenarios, such as:</p>
<ul>
<li>
<p><strong>Functions</strong> - It’s very common to have domain specific functions that can be helpful in different use cases. Instead of having to create them in each place separately, you can just create them once and share them with others.</p>
</li>
<li>
<p><strong>Queries</strong> - Those can be useful when you don’t want to persist a data set, but want to provide a recipe for creating it from other sources instead.</p>
</li>
</ul>
<h2 id="catalogs-support-in-flink-sql">Catalogs support in Flink SQL</h2>
<p>Starting from version 1.9, Flink has a set of Catalog APIs that allows to integrate Flink with various catalog implementations. With the help of those APIs, you can query tables in Flink that were created in your external catalogs (e.g. Hive Metastore). Additionally, depending on the catalog implementation, you can create new objects such as tables or views from Flink, reuse them across different jobs, and possibly even use them in other tools compatible with that catalog. In other words, you can see catalogs as having a two-fold purpose:</p>
<ul>
<li>
<p>Provide an out-of-the box integration with ecosystems such as RDBMSs or Hive that allows you to query external objects like tables, views, or functions with no additional connector configuration. The connector properties are automatically derived from the catalog itself.</p>
</li>
<li>
<p>Act as a persistent store for Flink-specific metadata. In this mode, we additionally store connector properties alongside the logical metadata (e.g. schema, object name). That approach enables you to, for example, store a full definition of a Kafka-backed table with records serialized with Avro in Hive that can be later on used by Flink. However, as it incorporates Flink-specific properties, it can not be used by other tools that leverage Hive Metastore.</p>
</li>
</ul>
<p>As of Flink 1.11, there are two catalog implementations supported by the community:</p>
<ol>
<li>
<p>A comprehensive Hive catalog</p>
</li>
<li>
<p>A Postgres catalog (preview, read-only, for now)</p>
</li>
</ol>
<div class="alert alert-info">
<p><span class="label label-info" style="display: inline-block"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> Note</span>
Flink does not store data at rest; it is a compute engine and requires other systems to consume input from and write its output. This means that Flink does not own the lifecycle of the data. Integration with Catalogs does not change that. Flink uses catalogs for metadata management only.</p>
</div>
<p>All you need to do to start querying your tables defined in either of these metastores is to create the corresponding catalogs with connection parameters. Once this is done, you can use them the way you would in any relational database management system.</p>
<div class="highlight"><pre><code class="language-sql"><span class="c1">-- create a catalog which gives access to the backing Postgres installation</span>
<span class="k">CREATE</span> <span class="k">CATALOG</span> <span class="n">postgres</span> <span class="k">WITH</span> <span class="p">(</span>
<span class="s1">&#39;type&#39;</span><span class="o">=</span><span class="s1">&#39;jdbc&#39;</span><span class="p">,</span>
<span class="s1">&#39;property-version&#39;</span><span class="o">=</span><span class="s1">&#39;1&#39;</span><span class="p">,</span>
<span class="s1">&#39;base-url&#39;</span><span class="o">=</span><span class="s1">&#39;jdbc:postgresql://postgres:5432/&#39;</span><span class="p">,</span>
<span class="s1">&#39;default-database&#39;</span><span class="o">=</span><span class="s1">&#39;postgres&#39;</span><span class="p">,</span>
<span class="s1">&#39;username&#39;</span><span class="o">=</span><span class="s1">&#39;postgres&#39;</span><span class="p">,</span>
<span class="s1">&#39;password&#39;</span><span class="o">=</span><span class="s1">&#39;example&#39;</span>
<span class="p">);</span>
<span class="c1">-- create a catalog which gives access to the backing Hive installation</span>
<span class="k">CREATE</span> <span class="k">CATALOG</span> <span class="n">hive</span> <span class="k">WITH</span> <span class="p">(</span>
<span class="s1">&#39;type&#39;</span><span class="o">=</span><span class="s1">&#39;hive&#39;</span><span class="p">,</span>
<span class="s1">&#39;property-version&#39;</span><span class="o">=</span><span class="s1">&#39;1&#39;</span><span class="p">,</span>
<span class="s1">&#39;hive-version&#39;</span><span class="o">=</span><span class="s1">&#39;2.3.6&#39;</span><span class="p">,</span>
<span class="s1">&#39;hive-conf-dir&#39;</span><span class="o">=</span><span class="s1">&#39;/opt/hive-conf&#39;</span>
<span class="p">);</span>
<span class="k">After</span> <span class="n">creating</span> <span class="n">the</span> <span class="n">catalogs</span><span class="p">,</span> <span class="n">you</span> <span class="n">can</span> <span class="n">confirm</span> <span class="n">that</span> <span class="n">they</span> <span class="k">are</span> <span class="n">available</span> <span class="k">to</span> <span class="n">Flink</span> <span class="k">and</span> <span class="n">also</span> <span class="n">list</span> <span class="n">the</span> <span class="n">databases</span> <span class="k">or</span> <span class="n">tables</span> <span class="k">in</span> <span class="k">each</span> <span class="k">of</span> <span class="n">these</span> <span class="n">catalogs</span><span class="p">:</span>
<span class="o">```</span><span class="k">sql</span>
<span class="o">&gt;</span> <span class="k">show</span> <span class="n">catalogs</span><span class="p">;</span>
<span class="n">default_catalog</span>
<span class="n">hive</span>
<span class="n">postgres</span>
<span class="c1">-- switch the default catalog to Hive</span>
<span class="o">&gt;</span> <span class="n">use</span> <span class="k">catalog</span> <span class="n">hive</span><span class="p">;</span>
<span class="o">&gt;</span> <span class="k">show</span> <span class="n">databases</span><span class="p">;</span>
<span class="k">default</span> <span class="c1">-- hive&#39;s default database</span>
<span class="o">&gt;</span> <span class="k">show</span> <span class="n">tables</span><span class="p">;</span>
<span class="n">dev_orders</span>
<span class="o">&gt;</span> <span class="n">use</span> <span class="k">catalog</span> <span class="n">postgres</span><span class="p">;</span>
<span class="o">&gt;</span> <span class="k">show</span> <span class="n">tables</span><span class="p">;</span>
<span class="n">prod_customer</span>
<span class="n">prod_nation</span>
<span class="n">prod_rates</span>
<span class="n">prod_region</span>
<span class="n">region_stats</span>
<span class="c1">-- desribe a schema of a table in Postgres, the Postgres types are automatically mapped to</span>
<span class="c1">-- Flink&#39;s type system</span>
<span class="o">&gt;</span> <span class="k">describe</span> <span class="n">prod_customer</span>
<span class="n">root</span>
<span class="o">|</span><span class="c1">-- c_custkey: INT NOT NULL</span>
<span class="o">|</span><span class="c1">-- c_name: VARCHAR(25) NOT NULL</span>
<span class="o">|</span><span class="c1">-- c_address: VARCHAR(40) NOT NULL</span>
<span class="o">|</span><span class="c1">-- c_nationkey: INT NOT NULL</span>
<span class="o">|</span><span class="c1">-- c_phone: CHAR(15) NOT NULL</span>
<span class="o">|</span><span class="c1">-- c_acctbal: DOUBLE NOT NULL</span>
<span class="o">|</span><span class="c1">-- c_mktsegment: CHAR(10) NOT NULL</span>
<span class="o">|</span><span class="c1">-- c_comment: VARCHAR(117) NOT NULL</span></code></pre></div>
<p>Now that you know which tables are available, you can write your first query.
In this scenario, we keep customer orders in Hive (<code>dev_orders</code>) because of their volume, and reference customer data in Postgres (<code>prod_customer</code>) to be able to easily update it. Let’s write a query that shows customers and their orders by region and order priority for a specific day.</p>
<div class="highlight"><pre><code class="language-sql"><span class="n">USE</span> <span class="k">CATALOG</span> <span class="n">postgres</span><span class="p">;</span>
<span class="k">SELECT</span>
<span class="n">r_name</span> <span class="k">AS</span> <span class="o">`</span><span class="n">region</span><span class="o">`</span><span class="p">,</span>
<span class="n">o_orderpriority</span> <span class="k">AS</span> <span class="o">`</span><span class="n">priority</span><span class="o">`</span><span class="p">,</span>
<span class="k">COUNT</span><span class="p">(</span><span class="k">DISTINCT</span> <span class="n">c_custkey</span><span class="p">)</span> <span class="k">AS</span> <span class="o">`</span><span class="n">number_of_customers</span><span class="o">`</span><span class="p">,</span>
<span class="k">COUNT</span><span class="p">(</span><span class="n">o_orderkey</span><span class="p">)</span> <span class="k">AS</span> <span class="o">`</span><span class="n">number_of_orders</span><span class="o">`</span>
<span class="k">FROM</span> <span class="o">`</span><span class="n">hive</span><span class="o">`</span><span class="p">.</span><span class="o">`</span><span class="k">default</span><span class="o">`</span><span class="p">.</span><span class="n">dev_orders</span> <span class="c1">-- we need to fully qualify the table in hive because we set the</span>
<span class="c1">-- current catalog to Postgres</span>
<span class="k">JOIN</span> <span class="n">prod_customer</span> <span class="k">ON</span> <span class="n">o_custkey</span> <span class="o">=</span> <span class="n">c_custkey</span>
<span class="k">JOIN</span> <span class="n">prod_nation</span> <span class="k">ON</span> <span class="n">c_nationkey</span> <span class="o">=</span> <span class="n">n_nationkey</span>
<span class="k">JOIN</span> <span class="n">prod_region</span> <span class="k">ON</span> <span class="n">n_regionkey</span> <span class="o">=</span> <span class="n">r_regionkey</span>
<span class="k">WHERE</span>
<span class="n">FLOOR</span><span class="p">(</span><span class="n">o_ordertime</span> <span class="k">TO</span> <span class="k">DAY</span><span class="p">)</span> <span class="o">=</span> <span class="k">TIMESTAMP</span> <span class="s1">&#39;2020-04-01 0:00:00.000&#39;</span>
<span class="k">AND</span> <span class="k">NOT</span> <span class="n">o_orderpriority</span> <span class="o">=</span> <span class="s1">&#39;4-NOT SPECIFIED&#39;</span>
<span class="k">GROUP</span> <span class="k">BY</span> <span class="n">r_name</span><span class="p">,</span> <span class="n">o_orderpriority</span>
<span class="k">ORDER</span> <span class="k">BY</span> <span class="n">r_name</span><span class="p">,</span> <span class="n">o_orderpriority</span><span class="p">;</span></code></pre></div>
<p>Flink’s catalog support also covers storing Flink-specific objects in external catalogs that might not be fully usable by the corresponding external tools. The most notable use case for this is, for example, storing a table that describes a Kafka topic in a Hive catalog. Take the following DDL statement, that contains a watermark declaration as well as a set of connector properties that are not recognizable by Hive. You won’t be able to query the table with Hive, but it will be persisted and can be reused by different Flink jobs.</p>
<div class="highlight"><pre><code class="language-sql"><span class="n">USE</span> <span class="k">CATALOG</span> <span class="n">hive</span><span class="p">;</span>
<span class="k">CREATE</span> <span class="k">TABLE</span> <span class="n">prod_lineitem</span> <span class="p">(</span>
<span class="n">l_orderkey</span> <span class="nb">INTEGER</span><span class="p">,</span>
<span class="n">l_partkey</span> <span class="nb">INTEGER</span><span class="p">,</span>
<span class="n">l_suppkey</span> <span class="nb">INTEGER</span><span class="p">,</span>
<span class="n">l_linenumber</span> <span class="nb">INTEGER</span><span class="p">,</span>
<span class="n">l_quantity</span> <span class="n">DOUBLE</span><span class="p">,</span>
<span class="n">l_extendedprice</span> <span class="n">DOUBLE</span><span class="p">,</span>
<span class="n">l_discount</span> <span class="n">DOUBLE</span><span class="p">,</span>
<span class="n">l_tax</span> <span class="n">DOUBLE</span><span class="p">,</span>
<span class="n">l_currency</span> <span class="n">STRING</span><span class="p">,</span>
<span class="n">l_returnflag</span> <span class="n">STRING</span><span class="p">,</span>
<span class="n">l_linestatus</span> <span class="n">STRING</span><span class="p">,</span>
<span class="n">l_ordertime</span> <span class="k">TIMESTAMP</span><span class="p">(</span><span class="mi">3</span><span class="p">),</span>
<span class="n">l_shipinstruct</span> <span class="n">STRING</span><span class="p">,</span>
<span class="n">l_shipmode</span> <span class="n">STRING</span><span class="p">,</span>
<span class="n">l_comment</span> <span class="n">STRING</span><span class="p">,</span>
<span class="n">l_proctime</span> <span class="k">AS</span> <span class="n">PROCTIME</span><span class="p">(),</span>
<span class="n">WATERMARK</span> <span class="k">FOR</span> <span class="n">l_ordertime</span> <span class="k">AS</span> <span class="n">l_ordertime</span> <span class="o">-</span> <span class="nb">INTERVAL</span> <span class="s1">&#39;5&#39;</span> <span class="n">SECONDS</span>
<span class="p">)</span> <span class="k">WITH</span> <span class="p">(</span>
<span class="s1">&#39;connector&#39;</span><span class="o">=</span><span class="s1">&#39;kafka&#39;</span><span class="p">,</span>
<span class="s1">&#39;topic&#39;</span><span class="o">=</span><span class="s1">&#39;lineitem&#39;</span><span class="p">,</span>
<span class="s1">&#39;scan.startup.mode&#39;</span><span class="o">=</span><span class="s1">&#39;earliest-offset&#39;</span><span class="p">,</span>
<span class="s1">&#39;properties.bootstrap.servers&#39;</span><span class="o">=</span><span class="s1">&#39;kafka:9092&#39;</span><span class="p">,</span>
<span class="s1">&#39;properties.group.id&#39;</span><span class="o">=</span><span class="s1">&#39;testGroup&#39;</span><span class="p">,</span>
<span class="s1">&#39;format&#39;</span><span class="o">=</span><span class="s1">&#39;csv&#39;</span><span class="p">,</span>
<span class="s1">&#39;csv.field-delimiter&#39;</span><span class="o">=</span><span class="s1">&#39;|&#39;</span>
<span class="p">);</span></code></pre></div>
<p>With <code>prod_lineitem</code> stored in Hive, you can now write a query that will enrich the incoming stream with static data kept in Postgres. To illustrate how this works, let’s calculate the item prices based on the current currency rates:</p>
<div class="highlight"><pre><code class="language-sql"><span class="n">USE</span> <span class="k">CATALOG</span> <span class="n">postgres</span><span class="p">;</span>
<span class="k">SELECT</span>
<span class="n">l_proctime</span> <span class="k">AS</span> <span class="o">`</span><span class="n">querytime</span><span class="o">`</span><span class="p">,</span>
<span class="n">l_orderkey</span> <span class="k">AS</span> <span class="o">`</span><span class="k">order</span><span class="o">`</span><span class="p">,</span>
<span class="n">l_linenumber</span> <span class="k">AS</span> <span class="o">`</span><span class="n">linenumber</span><span class="o">`</span><span class="p">,</span>
<span class="n">l_currency</span> <span class="k">AS</span> <span class="o">`</span><span class="n">currency</span><span class="o">`</span><span class="p">,</span>
<span class="n">rs_rate</span> <span class="k">AS</span> <span class="o">`</span><span class="n">cur_rate</span><span class="o">`</span><span class="p">,</span>
<span class="p">(</span><span class="n">l_extendedprice</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">l_discount</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">l_tax</span><span class="p">))</span> <span class="o">/</span> <span class="n">rs_rate</span> <span class="k">AS</span> <span class="o">`</span><span class="n">open_in_euro</span><span class="o">`</span>
<span class="k">FROM</span> <span class="n">hive</span><span class="p">.</span><span class="o">`</span><span class="k">default</span><span class="o">`</span><span class="p">.</span><span class="n">prod_lineitem</span>
<span class="k">JOIN</span> <span class="n">prod_rates</span> <span class="k">FOR</span> <span class="n">SYSTEM_TIME</span> <span class="k">AS</span> <span class="k">OF</span> <span class="n">l_proctime</span> <span class="k">ON</span> <span class="n">rs_symbol</span> <span class="o">=</span> <span class="n">l_currency</span>
<span class="k">WHERE</span>
<span class="n">l_linestatus</span> <span class="o">=</span> <span class="s1">&#39;O&#39;</span><span class="p">;</span></code></pre></div>
<p>The query above uses a <code>SYSTEM AS OF</code> <a href="https://ci.apache.org/projects/flink/flink-docs-release-1.11/dev/table/streaming/temporal_tables.html#temporal-table">clause</a> for executing a temporal join. If you’d like to learn more about the different kind of joins you can do in Flink I highly encourage you to check <a href="https://ci.apache.org/projects/flink/flink-docs-release-1.11/dev/table/sql/queries.html#joins">this documentation page</a>.</p>
<h2 id="conclusion">Conclusion</h2>
<p>Catalogs can be extremely powerful when building data platforms aimed at reusing the work of different teams in an organization. Centralizing the metadata is a common practice for improving productivity, security, and compliance when working with data.</p>
<p>Flink provides flexible metadata management capabilities, that aim at reducing the cumbersome, repetitive work needed before querying the data such as defining schemas, connection properties etc. As of version 1.11, Flink provides a native, comprehensive integration with Hive Metastore and a read-only version for Postgres catalogs.</p>
<p>You can get started with Flink and catalogs by reading <a href="https://ci.apache.org/projects/flink/flink-docs-release-1.11/dev/table/catalogs.html">the docs</a>. If you want to play around with Flink SQL (e.g. try out how catalogs work in Flink yourself), you can check <a href="https://github.com/fhueske/flink-sql-demo">this demo</a> prepared by our colleagues Fabian and Timo — it runs in a dockerized environment, and we used it for the examples in this blog post.</p>
</article>
</div>
<div class="row">
<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'stratosphere-eu'; // required: replace example with your forum shortname
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
</div>
</div>
</div>
</div>
</div>
<hr />
<div class="row">
<div class="footer text-center col-sm-12">
<p>Copyright © 2014-2019 <a href="http://apache.org">The Apache Software Foundation</a>. All Rights Reserved.</p>
<p>Apache Flink, Flink®, Apache®, the squirrel logo, and the Apache feather logo are either registered trademarks or trademarks of The Apache Software Foundation.</p>
<p><a href="/privacy-policy.html">Privacy Policy</a> &middot; <a href="/blog/feed.xml">RSS feed</a></p>
</div>
</div>
</div><!-- /.container -->
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.matchHeight/0.7.0/jquery.matchHeight-min.js"></script>
<script src="/js/codetabs.js"></script>
<script src="/js/stickysidebar.js"></script>
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-52545728-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>