<html>
<head>
    <base href="https://docs.jboss.org/author">
            <link rel="stylesheet" href="/author/s/en/2172/19/5/_/styles/combined.css?spaceKey=TEIID&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://docs.jboss.org/author/display/TEIID/Phoenix+Data+Sources">Phoenix Data Sources</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://docs.jboss.org/author/display/~kylin">Kylin Soong</a>
    </h4>
        <br/>
                         <h4>Changes (11)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >* Mapping Phoenix table to an existing HBase table <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">* Creaing Phoenix table for creating a new HBase table <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">* Creaing Phoenix table <br></td></tr>
            <tr><td class="diff-unchanged" > <br>h1. Configuring a Phoenix data source in JBoss/WildFly (later than JBoss AS 7) <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >* driver-name - The Driver name need to match the driver you deployed in above steps <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >* driver-class - The Driver Class, the value should be <span class="diff-changed-words"><span class="diff-added-chars"style="background-color: #dfd;">_</span>org.apache.phoenix.jdbc.PhoenixDriver<span class="diff-added-chars"style="background-color: #dfd;">_</span></span> <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-changed-lines" >* connection-url - The URL need to match the HBase zookeeper quorum server, the format like <span class="diff-changed-words"><span class="diff-added-chars"style="background-color: #dfd;">_</span>jdbc:phoenix</span> \[ :&lt;zookeeper quorum&gt; \[ :&lt;port number&gt; \] \[ :&lt;root node&gt; \] <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">\], &#39;jdbc:phoenix:127.0.0.1:2181&#39;</span> <span class="diff-added-words"style="background-color: #dfd;">\]_, &#39;_jdbc:phoenix:127.0.0.1:2181_&#39;</span> is a example <br></td></tr>
            <tr><td class="diff-unchanged" > <br>* user-name/password - The user credentials for Phoenix Connection <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >The second step is executing the DDL to map Phoenix table to an existing HBase table, the DDL can either be executed via [Phoenix Command Line|http://phoenix.apache.org/download.html], or executed by JDBC. <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">The Following is a example for mapping an existing HBase table, assume the Customer table, assume the Customer table is existing in HBase, it looks as below figure is existing in HBase, it looks as below figure <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">The Following is a example for mapping an existing HBase table, assume the Customer table, assume the _Customer_ table is existing in HBase, it looks as below: <br></td></tr>
            <tr><td class="diff-unchanged" > <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">Test <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">| Row Key | customer | sales | <br>| ROW_ID | name | city | product | amount | <br>| 101 | John White | Los Angeles, CA | Chairs | $400.00 | <br>| 102 | Jane Brown | Atlanta, GA | Lamps | $200.00 | <br>| 103 | Bill Green | Pittsburgh, PA | Desk | $500.00 | <br>| 104 | Jack Black | St. Louis, MO | Bed | $1,600.00 | <br></td></tr>
            <tr><td class="diff-unchanged" > <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">As depicted above, HBase _Customer_ table have 2 column families, _customer_ and _sales_, each has 2 column qualifiers, _name_, _city_, _product_ and _amount_ correspondingly. We can map this Table to Phoenix via DDL: <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">Test</span> <span class="diff-added-words"style="background-color: #dfd;"> </span> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{code} <br>CREATE TABLE IF NOT EXISTS &quot;Customer&quot;(&quot;ROW_ID&quot; VARCHAR PRIMARY KEY, &quot;customer&quot;.&quot;city&quot; VARCHAR, &quot;customer&quot;.&quot;name&quot; VARCHAR, &quot;sales&quot;.&quot;amount&quot; VARCHAR, &quot;sales&quot;.&quot;product&quot; VARCHAR) <br>{code} <br>For more about mapping Phoenix table to an existing HBase table please refer to [phoenix document|http://phoenix.apache.org/faq.html#How_I_map_Phoenix_table_to_an_existing_HBase_table]. <br> <br>h1. Creating Phoenix table <br> <br>For creating Phoenix table just like mapping to an existing HBase table, Phoenix will create any metadata (table, column families) that doesn’t exist. As above example, if Customer doesn&#39;t exist, the DDL <br> <br>{code} <br>CREATE TABLE IF NOT EXISTS &quot;Customer&quot;(&quot;ROW_ID&quot; VARCHAR PRIMARY KEY, &quot;customer&quot;.&quot;city&quot; VARCHAR, &quot;customer&quot;.&quot;name&quot; VARCHAR, &quot;sales&quot;.&quot;amount&quot; VARCHAR, &quot;sales&quot;.&quot;product&quot; VARCHAR) <br>{code} <br>will create _Customer_ table in HBase. <br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h1><a name="PhoenixDataSources-PhoenixDataSources"></a>Phoenix Data Sources</h1>

<p>Primary purpose of this article including:</p>
<ul>
        <li>Configuring a Phoenix data source in JBoss/WildFly Container(later than JBoss AS 7)</li>
</ul>


<ul>
        <li>Mapping Phoenix table to an existing HBase table</li>
</ul>


<ul>
        <li>Creaing Phoenix table</li>
</ul>


<h1><a name="PhoenixDataSources-ConfiguringaPhoenixdatasourceinJBoss%2FWildFly%28laterthanJBossAS7%29"></a>Configuring a Phoenix data source in JBoss/WildFly (later than JBoss AS 7)</h1>

<p>Configuring a Phoenix data source is nearly identical configuring a <a href="/author/display/TEIID/JDBC+Data+Sources" title="JDBC Data Sources">JDBC Data Sources</a>, first step is deploying the Phoenix driver jar, the following command using the CLI to deploy Phoenix driver</p>


<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
deploy /path/to/phoenix-[version]-client.jar
</pre>
</div></div>

<p>The Driver jar can be download from <a href="http://phoenix.apache.org/" class="external-link" rel="nofollow">phoenix document.</a></p>






<p>The second steps is creating the Data Source base on above deployed driver, also like creating <a href="/author/display/TEIID/JDBC+Data+Sources" title="JDBC Data Sources">JDBC Data Source</a>, execute the following CLI command:</p>


<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
/subsystem=datasources/data-source=phoenixDS:add(jndi-name=java:/phoenixDS,  driver-name=phoenix-[version].jar, driver-class=org.apache.phoenix.jdbc.PhoenixDriver, connection-url=jdbc:phoenix:{zookeeper quorum server},user-name={user}, password={password})
</pre>
</div></div>

<p>Please make sure the URL, Driver are configured correctly:</p>

<ul>
        <li>jndi-name - The JNDI name need to match the JNDI name you used in VDB</li>
</ul>


<ul>
        <li>driver-name - The Driver name need to match the driver you deployed in above steps</li>
</ul>


<ul>
        <li>driver-class - The Driver Class, the value should be <em>org.apache.phoenix.jdbc.PhoenixDriver</em></li>
</ul>


<ul>
        <li>connection-url - The URL need to match the HBase zookeeper quorum server, the format like <em>jdbc:phoenix [ :&lt;zookeeper quorum&gt; [ :&lt;port number&gt; ] [ :&lt;root node&gt; ] ]</em>, '<em>jdbc:phoenix:127.0.0.1:2181</em>' is a example</li>
</ul>


<ul>
        <li>user-name/password - The user credentials for Phoenix Connection</li>
</ul>


<h1><a name="PhoenixDataSources-MappingPhoenixtabletoanexistingHBasetable"></a>Mapping Phoenix table to an existing HBase table</h1>

<p>Mapping Phoenix table to an existing HBase table has 2 steps, the first step is installing phoenix-[version]-server.jar to the classpath of every HBase region server,an easy way to do this is to copy it into the HBase lib, more details please refer to <a href="http://phoenix.apache.org/download.html" class="external-link" rel="nofollow">phoenix document</a>.</p>

<p>The second step is executing the DDL to map Phoenix table to an existing HBase table, the DDL can either be executed via <a href="http://phoenix.apache.org/download.html" class="external-link" rel="nofollow">Phoenix Command Line</a>, or executed by JDBC.</p>

<p>The Following is a example for mapping an existing HBase table, assume the Customer table, assume the <em>Customer</em> table is existing in HBase, it looks as below:</p>


<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<td class='confluenceTd'> Row Key </td>
<td class='confluenceTd'> customer </td>
<td class='confluenceTd'> sales </td>
</tr>
<tr>
<td class='confluenceTd'> ROW_ID </td>
<td class='confluenceTd'> name </td>
<td class='confluenceTd'> city </td>
<td class='confluenceTd'> product </td>
<td class='confluenceTd'> amount </td>
</tr>
<tr>
<td class='confluenceTd'> 101 </td>
<td class='confluenceTd'> John White </td>
<td class='confluenceTd'> Los Angeles, CA </td>
<td class='confluenceTd'> Chairs </td>
<td class='confluenceTd'> $400.00 </td>
</tr>
<tr>
<td class='confluenceTd'> 102 </td>
<td class='confluenceTd'> Jane Brown </td>
<td class='confluenceTd'> Atlanta, GA </td>
<td class='confluenceTd'> Lamps </td>
<td class='confluenceTd'> $200.00 </td>
</tr>
<tr>
<td class='confluenceTd'> 103 </td>
<td class='confluenceTd'> Bill Green </td>
<td class='confluenceTd'> Pittsburgh, PA </td>
<td class='confluenceTd'> Desk </td>
<td class='confluenceTd'> $500.00 </td>
</tr>
<tr>
<td class='confluenceTd'> 104 </td>
<td class='confluenceTd'> Jack Black </td>
<td class='confluenceTd'> St. Louis, MO </td>
<td class='confluenceTd'> Bed </td>
<td class='confluenceTd'> $1,600.00 </td>
</tr>
</tbody></table>
</div>



<p>As depicted above, HBase <em>Customer</em> table have 2 column families, <em>customer</em> and <em>sales</em>, each has 2 column qualifiers, <em>name</em>, <em>city</em>, <em>product</em> and <em>amount</em> correspondingly. We can map this Table to Phoenix via DDL:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
CREATE TABLE IF NOT EXISTS "Customer"("ROW_ID" VARCHAR PRIMARY KEY, "customer"."city" VARCHAR, "customer"."name" VARCHAR, "sales"."amount" VARCHAR, "sales"."product" VARCHAR)
</pre>
</div></div>
<p>For more about mapping Phoenix table to an existing HBase table please refer to <a href="http://phoenix.apache.org/faq.html#How_I_map_Phoenix_table_to_an_existing_HBase_table" class="external-link" rel="nofollow">phoenix document</a>.</p>

<h1><a name="PhoenixDataSources-CreatingPhoenixtable"></a>Creating Phoenix table</h1>

<p>For creating Phoenix table just like mapping to an existing HBase table, Phoenix will create any metadata (table, column families) that doesn’t exist. As above example, if Customer doesn't exist, the DDL</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
CREATE TABLE IF NOT EXISTS "Customer"("ROW_ID" VARCHAR PRIMARY KEY, "customer"."city" VARCHAR, "customer"."name" VARCHAR, "sales"."amount" VARCHAR, "sales"."product" VARCHAR)
</pre>
</div></div>
<p>will create <em>Customer</em> table in HBase.</p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;" class="grey">
                        <a href="https://docs.jboss.org/author/users/removespacenotification.action?spaceKey=TEIID">Stop watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://docs.jboss.org/author/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
        <a href="https://docs.jboss.org/author/display/TEIID/Phoenix+Data+Sources">View Online</a>
        |
        <a href="https://docs.jboss.org/author/pages/diffpagesbyversion.action?pageId=88866974&revisedVersion=7&originalVersion=6">View Changes</a>
                |
        <a href="https://docs.jboss.org/author/display/TEIID/Phoenix+Data+Sources?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>