<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by mohammad H. AbdelQader on Medium]]></title>
        <description><![CDATA[Stories by mohammad H. AbdelQader on Medium]]></description>
        <link>https://medium.com/@moha.ajori?source=rss-e5c9f0ac9d6d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*joyiEZUJXtGO7o2e2E-l0w.jpeg</url>
            <title>Stories by mohammad H. AbdelQader on Medium</title>
            <link>https://medium.com/@moha.ajori?source=rss-e5c9f0ac9d6d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 17:44:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@moha.ajori/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Read data from Kafka topic using Oracle SQL Access to Kafka (OSAK)]]></title>
            <link>https://medium.com/@moha.ajori/read-data-from-kafka-topic-using-oracle-sql-access-to-kafka-osak-e881e16c522e?source=rss-e5c9f0ac9d6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e881e16c522e</guid>
            <category><![CDATA[oracle-database]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[osak]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[kafka]]></category>
            <dc:creator><![CDATA[mohammad H. AbdelQader]]></dc:creator>
            <pubDate>Wed, 01 Jul 2020 20:41:33 GMT</pubDate>
            <atom:updated>2020-07-01T20:41:33.818Z</atom:updated>
            <content:encoded><![CDATA[<p>Oracle SQL Access to Kafka (OSAK) enable external table to read record from <a href="https://kafka.apache.org/">Kafka</a> topics. Using OSAK we can read data, join data with Oracle table and load data into Oracle table.</p><p>Through this article I will install and configure OSAK. Reading CSV records from Kafka topics. Loading these data to Oracle table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*Fjgab_M1l139qiBMypJc2Q.png" /></figure><h3>Pre-requisties</h3><ul><li>Apache Kafka cluster 0.10.2 or later (version 2.13 is using in this article)</li><li><a href="https://www.oracle.com/database/">Oracle Database</a> 12.2 or later where OSAK will installed (version 18c is using in this article</li></ul><h3>Install and configure OSAK</h3><p>The following are the steps that we will do to install and configure OSAK:</p><ul><li>Downloading OSAK file and Unzip into database server</li><li>Verifying OSAK install kit</li><li>Configuring JAVA_HOME</li><li>Adding, configuring Kafka cluster</li><li>Configuring database user</li></ul><blockquote>Downloading OSAK file and Unzip into database server</blockquote><p>First, download new version of sqldeveloper from <a href="https://www.oracle.com/tools/downloads/sqldev-downloads.html"><em>link</em></a><em>.</em></p><p>Then, copy “orakafka.zip” file from “orakafka” directory inside sqldeveloper directory.</p><p>Then unzip “orakafka.zip” using unzip command</p><pre>[oracle@orcl18c oracle]$ unzip orakafka.zip</pre><p>After unzip file, run “orakafka_distro_install.sh” which will unpack kit and create required directories. The directory path is pass to command. The script will create ORA_KAFKA_HOME on this directory.</p><pre>[oracle@orcl18c orakafka-1.2.0]$ ./orakafka_distro_install.sh -p /u01/app/oracle/orakafka_distro_home</pre><pre>Step Create Product Home::</pre><pre>--------------------------------------------------------------</pre><pre>Step Create Product Home: completed.</pre><pre>PRODUCT_HOME=/u01/app/oracle/orakafka_distro_home/ora_kafka_home</pre><pre>Step Create app_data home::</pre><pre>--------------------------------------------------------------</pre><pre>..... creating /u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data and subdirectories</pre><pre>......Generated CONF_KIT_HOME_SCRIPT=/u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/scripts/configure_kit_home.sh</pre><pre>......Generated CONF_APP_DATA_HOME_SCRIPT=/u01/app/oracle/orakafka_distro_home/ora_kafka_home/configure_app_data_home.sh</pre><pre>Step Create app_data home: completed.</pre><pre>APP_DATA_HOME=/u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data</pre><pre>Step unzip_kit::</pre><pre>--------------------------------------------------------------</pre><pre>checking for existing binaries in /u01/app/oracle/orakafka_distro_home/ora_kafka_home/orakafka</pre><pre>.....unzip kit into /u01/app/oracle/orakafka_distro_home/ora_kafka_home/orakafka</pre><pre>Archive:  /home/oracle/orakafka/orakafka-1.2.0/orakafka.zip</pre><pre>creating: /u01/app/oracle/orakafka_distro_home/ora_kafka_home/orakafka/</pre><pre>inflating: /u01/app/oracle/orakafka_distro_home/ora_kafka_home/orakafka/README</pre><pre>creating: /u01/app/oracle/orakafka_distro_home/ora_kafka_home/orakafka/doc/</pre><pre>inflating: /u01/app/oracle/orakafka_distro_home/ora_kafka_home/orakafka/doc/README_INSTALL<br>.....</pre><pre>extracting: /u01/app/oracle/orakafka_distro_home/ora_kafka_home/orakafka/kit_version.txt</pre><pre>Step unzip_kit: completed.</pre><pre>Successfully installed orakafka kit in /u01/app/oracle/orakafka_distro_home/ora_kafka_home</pre><p>Them configure APP_DATA_HOME variable by run “configure_app_data_home.sh” from ora_kafka_home</p><pre>[oracle@orcl18c ora_kafka_home]$ ./configure_app_data_home.sh</pre><p>before start work with “ora_kafka.sh” script, we need to Check the java version on database server. OSAK need JAVA 1.8 and later</p><pre>[oracle@orcl18c ~]$ java -version</pre><pre>java version &quot;1.8.0_251&quot;</pre><pre>Java(TM) SE Runtime Environment (build 1.8.0_251-b08)</pre><pre>Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)</pre><p>Then Create database user for ORA_KAFKA packages and other objects</p><pre>SQL&gt; create user KAFKA_USER identified by kafka;</pre><pre>User created.</pre><pre>SQL&gt; grant connect,resource to kafka_user;</pre><pre>Grant succeeded.</pre><blockquote>Verifying OSAK install kit</blockquote><p>The script “orakafka.sh” will use for all the next operations. The script inside the ORA_KAFKA_HOME/bin directory</p><p>To verify OSAK install kit, run “orakafka.sh” with verify_install option</p><pre>[oracle@orcl18c bin]$ ./orakafka.sh verify_install</pre><pre>Check all files/dirs ownership - passed</pre><pre>Check directory privileges - passed</pre><pre>Check expected executable files - passed</pre><pre>The above information is written to /u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/logs/verify_install.log.2020.06.29-16.36.22</pre><pre>To setup Oracle SQL Access to Kafka for the first time, the &quot;setup_all&quot; command should be used</pre><blockquote>Configuring JAVA_HOME For OSAK</blockquote><p>on this step we will set JAVA_HOME for OSAK by use “set_java_home” option</p><pre>[oracle@orcl18c bin]$ ./orakafka.sh set_java_home -p /usr/lib/jvm/jdk1.8.0_251</pre><pre>Step1: Check for valid JAVA_HOME</pre><pre>--------------------------------------------------------------</pre><pre>Found /usr/lib/jvm/jdk1.8.0_251/bin/java, JAVA_HOME path is valid.</pre><pre>Step1 succeeded.</pre><pre>Step2: JAVA version check</pre><pre>--------------------------------------------------------------</pre><pre>java version &quot;1.8.0_251&quot;</pre><pre>Java(TM) SE Runtime Environment (build 1.8.0_251-b08)</pre><pre>Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)</pre><pre>Java version &gt;= 1.8</pre><pre>Step2 succeeded.</pre><pre>Step3: Creating configure_java.sh script</pre><pre>--------------------------------------------------------------</pre><pre>Wrote to /u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/scripts/configure_java.sh</pre><pre>Step3 succeeded.</pre><pre>Successfully configured JAVA_HOME in /u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/scripts/configure_java.sh</pre><pre>The above information is written to /u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/logs/set_java_home.log.2020.06.29-23.12.35</pre><blockquote>Adding , configuring Kafka cluster</blockquote><p>First, use “add_cluster” option to create a cluster filesystem configuration directory and generate DDL to create cluster configuration directory in database. we pass the cluster name parameter “KAFKACLU1”. This name will use in next operation</p><pre>[oracle@orcl18c bin]$ ./orakafka.sh add_cluster -c KAFKACLU1</pre><pre>Step1: Creation of filesystem cluster config directory</pre><pre>--------------------------------------------------------------</pre><pre>Filesystem cluster directory creation completed.</pre><pre>Configure security properties at /u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/clusters/KAFKACLU1/conf/orakafka.properties.</pre><pre>Step1 succeeded.</pre><pre>Step2: Generate DDL for creation of cluster config DB directory</pre><pre>--------------------------------------------------------------</pre><pre>Execute the following SQL script while connected as sysdba</pre><pre>to create cluster config database directory:</pre><pre>@/u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/scratch/orakafka_create_KAFKACLU1_CONF_DIR.sql</pre><pre>Step2 successfully generated script.</pre><pre>***********SUMMARY************</pre><pre>TODO tasks:</pre><pre>1. Configure security properties at /u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/clusters/KAFKACLU1/conf/orakafka.properties</pre><pre>2. Execute the following SQL while connected as sysdba:</pre><pre>@/u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/scratch/orakafka_create_KAFKACLU1_CONF_DIR.sql</pre><pre>The above information is written to /u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/logs/add_cluster.log.2020.06.29-23.14.04</pre><p>If you have secured your Apache Kafka cluster, you need to configure security properties on file “orakafka.properties” . The file path list in task 1 on TODO tasks</p><p>For more information, refer to the <a href="https://kafka.apache.org/documentation/#security">Apache Kafka Security</a> information.</p><p>Second, connect to database as <strong>sysdba</strong> and execute script that mention in task 2 in TODO tasks</p><pre>[oracle@orcl18c bin]$ sqlplus / as sysdba</pre><pre>SQL*Plus: Release 18.0.0.0.0 - Production on Mon Jun 29 23:14:24 2020</pre><pre>Version 18.3.0.0.0</pre><pre>Copyright (c) 1982, 2018, Oracle.  All rights reserved.</pre><pre>Connected to:</pre><pre>Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production</pre><pre>Version 18.3.0.0.0</pre><pre>SQL&gt; alter session set container=kafkapdb;</pre><pre>Session altered.</pre><pre>SQL&gt;@/u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/scratch/orakafka_create_KAFKACLU1_CONF_DIR.sql</pre><pre>Creating database directory &quot;KAFKACLU1_CONF_DIR&quot;..</pre><pre>Directory created.</pre><pre>The above information is written to /u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/logs/orakafka_create_KAFKACLU1_CONF_DIR.log</pre><pre>Disconnected from Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production</pre><pre>Version 18.3.0.0.0</pre><p>Now we can test our cluster configuration. The command will connect to Kafka cluster and get topics using bootstrap server</p><p>To test cluster configuration, use “test_cluster” option with cluster name and bootstrap server information</p><pre>[oracle@orcl18c bin]$ ./orakafka.sh test_cluster -c KAFKACLU1 -b 192.168.8.100:9092</pre><pre>Kafka cluster configuration test succeeded.</pre><pre>Kafka cluster configuration test - &quot;KAFKACLU1&quot;</pre><pre>------------------------------------------------------</pre><pre>KAFKA_BOOTSTRAP_SERVERS=192.168.8.100:9092</pre><pre>LOCATION_FILE=&quot;/u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/clusters/KAFKACLU1/logs/orakafka_stream_KAFKACLU1.loc&quot;</pre><pre>ora_kafka_operation=metadata</pre><pre>kafka_bootstrap_servers=192.168.8.100:9092</pre><pre>List topics output:</pre><pre>tweet_topic,6</pre><pre>wordcount-application-Counts-changelog,3</pre><pre>...</pre><pre>For full log, please look at /u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/clusters/KAFKACLU1/logs/test_KAFKACLU1.log.2020.06.29-23.18.34</pre><pre>Test of Kafka cluster configuration for &quot;KAFKACLU1&quot; completed.</pre><pre>The above information is written to /u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/logs/test_cluster.log.2020.06.29-23.18.34</pre><blockquote>Configuring database user</blockquote><p>First, use “adduser_cluster” option to grant required permissions for database user on Kafka cluster.</p><pre>[oracle@orcl18c bin]$  ./orakafka.sh adduser_cluster -c KAFKACLU1 -u KAFKA_USER</pre><pre>Step1: Generate DDL to grant permissions on cluster configuration directory to &quot;KAFKA_USER&quot;</pre><pre>--------------------------------------------------------------Execute the following script while connected as sysdba</pre><pre>to grant permissions on cluster conf directory :</pre><pre>@/u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/scratch/orakafka_adduser_cluster_KAFKACLU1_user1.sql</pre><pre>Step1 successfully generated script.</pre><pre>***********SUMMARY************</pre><pre>TODO tasks:</pre><pre>1. Execute the following SQL while connected as sysdba:</pre><pre>@/u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/scratch/orakafka_adduser_cluster_KAFKACLU1_user1.sql</pre><pre>The above information is written to /u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/logs/adduser_cluster.log.2020.06.29-23.21.03</pre><p>The command generates DDL to grant required permission. we must run task 1 script as <strong>sysdba</strong>.</p><pre>SQL&gt;@/u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/scratch/orakafka_adduser_cluster_KAFKACLU1_user1.sql</pre><pre>PL/SQL procedure successfully completed.</pre><pre>Granting permissions on &quot;KAFKACLU1_CONF_DIR&quot; to &quot;KAFKA_USER&quot;</pre><pre>Grant succeeded.</pre><pre>The above information is written to /u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/logs/orakafka_adduser_cluster_KAFKACLU1_user1.log</pre><pre>Disconnected from Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production<br>Version 18.3.0.0.0</pre><p>Second, we use “install” option to generate DLL to install ORA_KAFKA package in database user and create required directories.</p><p>The path for filesystem location pass to command which will use for log and ORA_KAFKA files</p><pre>[oracle@orcl18c bin]$ ./orakafka.sh install -u KAFKA_USER -r /u01/app/oracle/orakafka_distro_home/ora_kafka_home/user_data_dir</pre><pre>Step1: Creation of filesystem location and default directories<br>--------------------------------------------------------------</pre><pre>Created filesystem location directory at /u01/app/oracle/orakafka_distro_home/ora_kafka_home/user_data_dir/orakafka_location_dir</pre><pre>Created filesystem default directory at /u01/app/oracle/orakafka_distro_home/ora_kafka_home/user_data_dir/orakafka_default_dir</pre><pre>Step1 succeeded.</pre><pre>Step2: Generate DDL for creation of DB location and default directories<br>--------------------------------------------------------------</pre><pre>Execute the following SQL script while connected as sysdba</pre><pre>to setup database directories:</pre><pre>@/u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/scratch/setup_db_dirs_user1.sql</pre><pre>On failure, to cleanup location and default directory setup, please run &quot;./orakafka.sh uninstall -u &#39;KAFKA_USER&#39;&quot;</pre><pre>Step2 successfully generated script.</pre><pre>Step3: Install ORA_KAFKA package in &quot;KAFKA_USER&quot; user schema</pre><pre>--------------------------------------------------------------</pre><pre>Execute the following script in user schema &quot;KAFKA_USER&quot; to</pre><pre>install ORA_KAFKA package in the user schema</pre><pre>@/u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/scratch/install_orakafka_user1.sql</pre><pre>On failure, to cleanup ORA_KAFKA package from user schema, please run &quot;./orakafka.sh uninstall -u &#39;KAFKA_USER&#39;&quot;</pre><pre>Step3 successfully generated script.</pre><pre>***********SUMMARY************</pre><pre>TODO tasks:<br>1. Execute the following SQL while connected as sysdba:</pre><pre>@/u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/scratch/setup_db_dirs_user1.sql</pre><pre>2. Execute the following SQL in user schema:</pre><pre>@/u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/scratch/install_orakafka_user1.sql</pre><pre>The above information is written to /u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/logs/install.log.2020.06.29-23.25.46</pre><p>Then, run script of task 1 as <strong>sysdba</strong></p><pre>SQL&gt;@/u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/scratch/setup_db_dirs_user1.sql</pre><pre>Checking if user exists..</pre><pre>PL/SQL procedure successfully completed.</pre><pre>Creating location and default directories..</pre><pre>PL/SQL procedure successfully completed.</pre><pre>Directory created.</pre><pre>Directory created.</pre><pre>Grant succeeded.</pre><pre>Grant succeeded.</pre><pre>Creation of location dir &quot;KAFKA_USER_KAFKA_LOC_DIR&quot; and default dir &quot;KAFKA_USER_KAFKA_DEF_DIR&quot; completed.</pre><pre>Grant of required permissions on &quot;KAFKA_USER_KAFKA_LOC_DIR&quot;,&quot;KAFKA_USER_KAFKA_DEF_DIR&quot; to &quot;KAFKA_USER&quot; completed.</pre><pre>The above information is written to /u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/logs/setup_db_dirs_user1.log</pre><pre>Disconnected from Oracle</pre><p>The task 2 in TODO tasks need to run through <strong>database user that contain OSAK package and objects (not sysdba)</strong></p><pre>[oracle@orcl18c bin]$ sqlplus kafka_user@kafkapdb</pre><pre>SQL*Plus: Release 18.0.0.0.0 - Production on Mon Jun 29 23:28:54 2020 Version 18.3.0.0.0<br>Copyright (c) 1982, 2018, Oracle.  All rights reserved.<br>Connected to:<br>Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production Version 18.3.0.0.0</pre><pre>SQL&gt;@/u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/scratch/install_orakafka_user1.sql</pre><pre>Verifying user schema..</pre><pre>PL/SQL procedure successfully completed.</pre><pre>Verifying that location and default directories are accessible..</pre><pre>PL/SQL procedure successfully completed.</pre><pre>Installing ORA_KAFKA package in user schema..</pre><pre>.. Creating ORA_KAFKA artifacts</pre><pre>Table created.</pre><pre>Table created.</pre><pre>Table created.</pre><pre>Table created.</pre><pre>Package created.</pre><pre>No errors.</pre><pre>Package created.</pre><pre>No errors.</pre><pre>Package body created.</pre><pre>No errors.</pre><pre>Package body created.</pre><pre>No errors.</pre><pre>The above information is written to /u01/app/oracle/orakafka_distro_home/ora_kafka_home/app_data/logs/install_orakafka_user1.log</pre><pre>Disconnected from Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production Version 18.3.0.0.0</pre><p>The OSAK support two of record types:</p><ul><li>CSV (delimited text)</li><li>JSON</li></ul><p>In this demo we will produce comma separated text (CSV) to Kafka topics. Then query this records from Oracle database using OSAK</p><p>Before data can be read from a Kafka topic, register the cluster and assign a unique name. The following example registers the cluster KAFKACLU1</p><p>connect to database user using sqlplus and execute following</p><pre>BEGIN<br>ORA_KAFKA.REGISTER_CLUSTER<br>(&#39;KAFKACLU1&#39;, -- cluster name<br>&#39;192.168.8.100:9092&#39;, -- bootstrap server<br>&#39;KAFKA_USER_KAFKA_DEF_DIR&#39;, -- default directory for external table<br>&#39;KAFKA_USER_KAFKA_LOC_DIR&#39;,<br>&#39;KAFKACLU1_CONF_DIR&#39;, --config dir for cluster<br>&#39;Testing DBMS_KAFKA&#39;); --description <br>END;<br>/</pre><p>The next step is to create OSAK views that map to the Kafka topic. When the Kafka record format is CSV or delimited text, before creating the views, you must create a reference table whose shape is mapped to records in the Kafka topic.</p><p>The reference table describes the shape of the CSV data and is used to create OSAK external tables and views over the data</p><p><strong><em>NOTE</em></strong><em>: The order of the columns in the reference table must match the order of the fields in the Kafka record.</em></p><p>if the Kafka record format is JSON_VARCHAR2, a reference table should be passed as NULL.</p><p>For our demo, the table refer to customer table. we will create customer table in database schema. This table will use as reference table</p><pre>CREATE TABLE customers (<br>id int,<br>first_name varchar2(50),<br>last_name varchar2(50),<br>email varchar2(50),<br>gender varchar2(6)<br>);</pre><p>Next, create view use “ORA_KAFKA.CREATE_VIEWS” procedure</p><pre>DECLARE<br>views_created INTEGER;<br>application_id VARCHAR2(128);</pre><pre>BEGIN<br>ORA_KAFKA.CREATE_VIEWS<br>(&#39;KAFKACLU1&#39;, -- cluster name<br>&#39;QUERYAPP&#39;, -- group name (this use to create views use this name)<br>&#39;CUST_TOPIC&#39;, -- kafka topics<br>&#39;CSV&#39;, -- format type<br>&#39;CUSTOMERS&#39;, -- database reference table<br>views_created, -- output<br>application_id); --output<br>dbms_output.put_line(&#39;views created  = &#39; || views_created);<br>dbms_output.put_line(&#39;application id = &#39; || application_id);<br>END;<br>/</pre><p>This will create view for each topic partition. for our demo the topic created with 3 partition we will have three views.</p><p>The name of each view will be KV_&lt;CLUSTER_NAME&gt;_&lt;GROUP_NAME&gt;_TOPIC_&lt;NUM_OF_PARTITION&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*WBae05HPfDggILrfJhzjkw.png" /></figure><p>The structure of view</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mcqwG4-4iNe8Z58j52Qifg.png" /></figure><p>where <strong><em>KAFKA$PARTITION </em></strong>is the Kafka partition id, <strong><em>KAFKA$OFFSET </em></strong>is the offset of the Kafka record and <strong><em>KAFKA$EPOCH_TIMESTAMP</em></strong> is the timestamp of the Kafka record. The remaining columns represent the fields in the CSV data.</p><p>The following video shown how we query return records from Kafka topic</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FB02njI8rKqA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DB02njI8rKqA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FB02njI8rKqA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ade3a0c4993b82c4c04aed4fa5f4bdc/href">https://medium.com/media/9ade3a0c4993b82c4c04aed4fa5f4bdc/href</a></iframe><blockquote>Loading data to Oracle database table</blockquote><p>The ORA_KAFKA.LOAD_TABLE procedure loads data from a Kafka topic into a database table. This procedure creates a view that is used internally and maps to all partitions of the Kafka topic.</p><p>The view is not deleted at the end of the call procedure. So when call procedure again, it continue from last point.</p><p>we can call this procedure in loop To continuously load Kafka data into the database.</p><pre>DECLARE<br>num_records_loaded INT;<br>BEGIN<br>ORA_KAFKA.LOAD_TABLE<br>(&#39;KAFKACLU1&#39;,<br>&#39;LOADAPP&#39;,<br>&#39;CUST_TOPIC&#39;,<br>&#39;CSV&#39;,<br>&#39;CUSTOMERS&#39;,<br>num_records_loaded);<br>dbms_output.put_line(&#39;Kafka records loaded = &#39; || num_records_loaded);<br>COMMIT;<br>END;<br>/</pre><p>The following video shown how to load data from Kafka topic to Oracle database table</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F2lnhUVDCz1I%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D2lnhUVDCz1I&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F2lnhUVDCz1I%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/978b6aedf47fcac875164c6cce4f3f7e/href">https://medium.com/media/978b6aedf47fcac875164c6cce4f3f7e/href</a></iframe><p><strong><em>Notes</em></strong></p><ul><li>To work as continuous stream, we need to use LOOP logic with call LOAD_TABLE procedure or use INIT_OFFSET, NEXT_OFFSET and UPDATE_OFFSET procedures</li><li>we can query specific Kafka offset or timestamp using SEEK_OFFSET, SEEK_OFFSET_TS</li></ul><h3>References</h3><ul><li><a href="https://docs.oracle.com/en/database/oracle/sql-developer/20.2/rptug/sql-developer-concepts-usage.html#GUID-5E6C990B-B64D-4328-948C-CB457A0B02DF">User&#39;s Guide</a></li><li><a href="https://kafka.apache.org/documentation/#security">Apache Kafka</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e881e16c522e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Monitoring Exadata using Grafana-prometheus with Docker]]></title>
            <link>https://medium.com/@moha.ajori/monitoring-exadata-using-grafana-prometheus-with-docker-c40af3bfdf9b?source=rss-e5c9f0ac9d6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c40af3bfdf9b</guid>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[oracle]]></category>
            <category><![CDATA[prometheus]]></category>
            <category><![CDATA[exadata]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[mohammad H. AbdelQader]]></dc:creator>
            <pubDate>Mon, 17 Feb 2020 08:35:26 GMT</pubDate>
            <atom:updated>2020-02-17T09:44:06.601Z</atom:updated>
            <content:encoded><![CDATA[<p>In this tutorial we are going to monitor Oracle E<a href="https://www.oracle.com/database/technologies/exadata.html">xadata</a> machine using <a href="https://grafana.com/">Grafana</a></p><p>We will use custom python script to take metrics from Exadata database then store them into <a href="https://prometheus.io/">Prometheus</a> (A time series database used to store the metrics and value of these metrics). After that we will build sample dashboard to monitor exported Exadata metrics.</p><h3>How-To-Guides</h3><p>we will go through the following steps:</p><ul><li>Run python script in one of exadata DB node</li><li>Build <a href="https://www.docker.com/">docker </a>image that contains Prometheus and Grafana</li><li>Create prometheus data source in Grafana</li><li>Import sample dashboard using Grafana</li></ul><blockquote>Run python script in one of exadata DB node</blockquote><p>01. Download python scripts from <a href="https://github.com/moha08/Exadata_Metric_Dashboard/tree/master/exadata_exporter">link</a>, then copy them to any exadata DB node ( the script run in python version 2.6 )</p><p>02. Install <a href="https://github.com/prometheus/client_python">prometheus_client </a>library in exadata node. ( if you don’t have pip package, you can install it using this <a href="https://pip.pypa.io/en/stable/installing/">link</a>)</p><pre># pip install prometheus_client</pre><p>03. Go to scripts directory and run python script</p><pre># nohup python exa_exporter.py &amp;</pre><blockquote>You need to ensure the file /root/cell_group and /root/db_group that contain list of you database node and storage node exists. If not you need to modify list_of_commands.py file with your files path</blockquote><blockquote>Build docker image that contain Prometheus and Grafana</blockquote><p>01. Download all required files from this <a href="https://github.com/moha08/Exadata_Metric_Dashboard/tree/master/prometheus_grafana_image">link</a> and then put all in directory on machine contains docker service.</p><p>02. Replace “&lt;Exadata node ip&gt;” in prometheus.yaml file with Exadata DB node IP address ( node where the python script running)</p><p>03. Build docker image from docker file</p><p>Go to Docker.file directory then</p><pre># docker build -t prometheus_exa .</pre><p>After build complete, we need to run container for this image</p><pre># docker run -name prom_exa -d -p 9090:9090 -p 3000:3000 prometheus_exa</pre><p>Check the container status and get container ID</p><pre># docker ps -a</pre><p>Finally we need to start grafana (replace &lt;container ID&gt; with your container ID)</p><pre># docker exec -it &lt;container ID&gt; /etc/init.d/grafana-server start</pre><blockquote>Check prometheus &amp; Grafana portal</blockquote><h4>Check prometheus Portal</h4><p>Go to <a href="http://192.168.215.216:9090/targets">http://&lt;your IP&gt;:9090/targets</a> and check Targets, we must have exadata target which get data from our exadata node</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uYvOvIA6LKe4sCDJAQ5A1w.png" /></figure><h4>Check Grafana Portal</h4><p>Go to http://&lt;your IP&gt;:3000</p><p>The default username and password is admin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GfKvfnJplaXXVZw5tq4VfQ.png" /></figure><p>After login</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5CxeEqytfT3iqP4qJbp2VQ.png" /></figure><blockquote>Create data source in Grafana</blockquote><p>From garafan portal, Click on “Add data source” icon</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k6ooFbTInDyHQ6JHZ47dFw.png" /></figure><p>Then choose “Prometheus” data source from list</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kpLi_VM_yhcPr_n1kwvRbQ.png" /></figure><p>Then we to rename data source to new name “exadata” and add our Prometheus URL (<a href="http://127.0.0.1:3000/">http://&lt;your IP&gt;:9090</a>) the click “Save &amp; Test” button to ensure it is work fine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t3iLSQ-AferFjJ1L8N-F5Q.png" /></figure><blockquote>Import dashboard using Grafana</blockquote><p>I created sample dashboard to monitor CPU, Memory and Temperature of exadata servers.</p><p>we need to download dashboard from <a href="https://github.com/moha08/Exadata_Metric_Dashboard/blob/master/Exadata_dashboard.json">Link</a>, Then import dashboard as below:</p><p>01. Go to Grafana portal home page , then click in “New dashboard” icon</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nTTO-1H1sbRrF2dE4rW2Cg.png" /></figure><p>02. Click in “New dashboard” menu</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-0an83NJVf0T70oFZ8pjeQ.png" /></figure><p>Then click on “Import dashboard”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bM9tUgkYTA_2m8AOP3TMKg.png" /></figure><p>After that you need to upload downloaded dashboard JSON file and select our data source “exadata”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_YJfdTY3OUrfodK4_CurdA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hhsAR36vxLV9Ta6EjD-ePw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rCVwRjL-OBDRTtIxF-RIuA.png" /></figure><p>Finally, After click “Import” button, the dashboard will show</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X-R5azrH4vPSeQZZCx44Ug.png" /></figure><p>You can use any <a href="https://docs.oracle.com/en/engineered-systems/exadata-database-machine/sagug/exadata-storage-server-monitoring.html#GUID-B52267F8-FAD9-4A86-9D84-81792A914C94">exadata metrics</a> to build your own dashboard, for example i built dashboard to Monitor the number of megabytes that allocated in flash cache and compare it with the number of megabytes I/O per second that happen in specific <a href="https://docs.oracle.com/database/121/CNCPT/cdbovrvw.htm#CNCPT89234">Pluggable database</a> in specific Exadata storage server</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eux--D4avbLz_S7-1EIjQA.png" /></figure><h3>References</h3><ul><li><a href="https://www.oracle.com/database/technologies/exadata.html">Oracle Exadata Database Machine</a></li><li><a href="https://prometheus.io/">Prometheus - Monitoring system &amp; time series database</a></li><li><a href="https://grafana.com/">Grafana: The open and composable observability platform | Grafana Labs</a></li><li><a href="https://www.docker.com/">Docker: Accelerated Container Application Development</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c40af3bfdf9b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Query ORACLE Database Data Using GraphQL-Python]]></title>
            <link>https://medium.com/analytics-vidhya/query-oracle-database-data-using-graphql-python-2c504cc2d343?source=rss-e5c9f0ac9d6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c504cc2d343</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[oracle]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[mohammad H. AbdelQader]]></dc:creator>
            <pubDate>Thu, 21 Nov 2019 07:43:11 GMT</pubDate>
            <atom:updated>2019-11-27T05:03:47.742Z</atom:updated>
            <content:encoded><![CDATA[<p>In This tutorial we are going to implement <a href="https://graphql.org/">GraphQL </a>server using <a href="https://www.python.org/">python </a>that query data from <a href="https://www.oracle.com/database/">Oracle </a>database tables</p><h3>What is a GraphQL?</h3><p>GraphQL is a query language for your API, and a server-side runtime for executing queries by using a type system you define for your data. GraphQL isn’t tied to any specific database or storage engine and is instead backed by your existing code and data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/0*SV65uTV9kjjWfWrf.png" /><figcaption>GraphQL Architecture</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eol1cUMflNxCbRWj.png" /><figcaption>GraphQL Architecture</figcaption></figure><h3><strong>Why GraphQL ??</strong></h3><ul><li>With GraphQL , You send query to API and get exactly what you need, nothing less and nothing more</li><li>GraphQL minimizes the amount of data which is transferred by selective about the data depending on the client application’s needs. A mobile client can fetch less information, because it may not be needed on a small screen compared to the larger screen for the web application.</li><li>Realtime Updates with Subscriptions, so When a client subscribes to an event, it will initiate and hold a steady connection to the server. Whenever that particular event then actually happens, the server pushes the corresponding data to the client. Unlike queries and mutations that follow a typical “request-response-cycle”, subscriptions represent a stream of data sent over to the client</li></ul><blockquote>This is a simple overview of the concepts, but it should be enough to go through the tutorial. You can read more about it <a href="https://graphql.org/learn/">here</a> and <a href="https://www.howtographql.com/">here</a></blockquote><h3>GraphQL Python Servers</h3><p>GraphQL support more than one libraries like Python, java, C#/.NET and <a href="https://graphql.org/code/#server-libraries">more</a>.</p><p>In this article we will use python server. There is <a href="http://graphene-python.org/">Graphene</a> and <a href="http://docs.graphene-python.org/projects/django/en/latest/">Graphene-Django</a>, exposing a simple and powerful API for creating GraphQL servers.</p><h3>Prerequisites</h3><ul><li>Python with django,graphene-django, django-filter and django-graphql libraries</li><li>HR sample schema in Oracle database</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BU4mIqfeJpRpnlolYu1IAg.png" /><figcaption>HR schema Diagram</figcaption></figure><h3>How To Guide</h3><h4>Create graphoracle project in django</h4><p>First we need to create django project. I created project called graphoracle</p><pre>(base) D:\django-graphql&gt;django-admin startproject graphoracle</pre><p>The command will create required libraries and create django project.</p><p>After project created we can run django server</p><pre>(base) D:\django-graphql&gt;python manage.py runserver</pre><p>To test, we can access <a href="http://localhost:8000/">http://localhost:8000</a> address. The following page must return</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zgSDCSfb1uFVaRRz.png" /></figure><blockquote><strong><em>You can find project files in </em></strong><a href="https://github.com/moha08/graporacle"><strong><em>github repo</em></strong></a></blockquote><h4>Modify settings.py file for graphoracle project</h4><p>We need to add the following settings for project:</p><ul><li>Add Oracle database connection setting</li></ul><p>we specify the database server ,port, service name ,username and password in this setting</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e89a30da8dd5f19715c9e5dfa6347792/href">https://medium.com/media/e89a30da8dd5f19715c9e5dfa6347792/href</a></iframe><ul><li>Add graphene package and schema path</li></ul><p>We must added the graphene_django in INSTALLED_APPS list. Also, we define the SCHEMA that we will used inside GRAPHENE setting</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85d0fa64f6fc72ea93b611f2f75595e2/href">https://medium.com/media/85d0fa64f6fc72ea93b611f2f75595e2/href</a></iframe><h4>Create hr app in graphoracle project</h4><p>The next step is to create hr application inside our project which will contain our models and schemas</p><pre>(base) D:\django-graphql\graphoracle&gt;python manage.py startapp hr<br>(base) D:\django-graphql\graphoracle&gt;cd hr<br>(base) D:\django-graphql\graphoracle\hr&gt;dir<br> Volume in drive D is DataDisk<br> Volume Serial Number is 88F9-D7BD</pre><pre>Directory of D:\django-graphql\graphoracle\hr</pre><pre>11/19/2019  09:49 AM    &lt;DIR&gt;          .<br>11/19/2019  09:49 AM    &lt;DIR&gt;          ..<br>11/19/2019  09:49 AM                66 admin.py<br>11/19/2019  09:49 AM                84 apps.py<br>11/19/2019  09:49 AM    &lt;DIR&gt;          migrations<br>11/19/2019  09:49 AM                60 models.py<br>11/19/2019  09:49 AM                63 tests.py<br>11/19/2019  09:49 AM                66 views.py<br>11/19/2019  09:49 AM                 0 __init__.py<br>               6 File(s)            339 bytes<br>               3 Dir(s)  23,212,933,120 bytes free</pre><h4>Inspect database tables using <a href="https://docs.djangoproject.com/en/2.2/howto/legacy-databases/">inspectdb </a>tool</h4><p>This is a great tool that will get all tables from database and build class for each table and define filed for each column.</p><pre>(base) D:\django-graphql\graphoracle&gt; python manage.py inspectdb &gt; hr\models.py</pre><p>After inspect finish, we must check models that created. sometimes we need to make changes depend in our tables</p><p>Following is sample of models.py file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f3f2b2ea46c0985f79e6ce94aae4fd4/href">https://medium.com/media/0f3f2b2ea46c0985f79e6ce94aae4fd4/href</a></iframe><h4>Migrate graphoracle project with database</h4><p>We will run two django scripts:</p><ul><li>makemigrations: This script will generate the required SQL commands that need to run in database</li><li>migrate This will execute the generated SQL commands. When run this script the django will create some tables inside database. These tables used from django project</li></ul><pre>(base) D:\django-graphql\graphoracle&gt;python manage.py makemigrations<br>No changes detected</pre><pre>(base) D:\django-graphql\graphoracle&gt;python manage.py migrate<br>Operations to perform:<br>  Apply all migrations: admin, auth, contenttypes, sessions<br>Running migrations:<br>  Applying contenttypes.0001_initial... OK<br>  Applying auth.0001_initial... OK<br>  Applying admin.0001_initial... OK<br>  Applying admin.0002_logentry_remove_auto_add... OK<br>  Applying admin.0003_logentry_add_action_flag_choices... OK<br>  Applying contenttypes.0002_remove_content_type_name... OK<br>  Applying auth.0002_alter_permission_name_max_length... OK<br>  Applying auth.0003_alter_user_email_max_length... OK<br>  Applying auth.0004_alter_user_username_opts... OK<br>  Applying auth.0005_alter_user_last_login_null... OK<br>  Applying auth.0006_require_contenttypes_0002... OK<br>  Applying auth.0007_alter_validators_add_error_messages... OK<br>  Applying auth.0008_alter_user_username_max_length... OK<br>  Applying auth.0009_alter_user_last_name_max_length... OK<br>  Applying auth.0010_alter_group_name_max_length... OK<br>  Applying auth.0011_update_proxy_permissions... OK<br>  Applying sessions.0001_initial... OK</pre><h4>Add hr app to settings.py file</h4><p>In this step we will add hr application in our project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9aca3a60c90c21a62ef06f0052e9e012/href">https://medium.com/media/9aca3a60c90c21a62ef06f0052e9e012/href</a></iframe><blockquote>In GraphQL, a <em>Type</em> is an object that may contain multiple <em>fields</em>. Each field is calculated through <em>resolvers</em>, that returns a value. A collection of types is called a <em>schema</em>. Every schema has a special type called <em>query</em> for getting data from the server.</blockquote><h4>Create GraphQL schema class</h4><p>We need to create schema.py file inside hr application directory then create DjangoObjectType ( a custom type available in Graphene Django) for each database object defined inside models.py</p><p>Also, we need to create Query class which contains resolver method for each schema.</p><p>Following are example from schema.py file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f509169974033ae8a79102bf26d664b/href">https://medium.com/media/6f509169974033ae8a79102bf26d664b/href</a></iframe><h4>Create schema class in graphoracle project</h4><p>Why creating another schema class with Query class inside? This class just inherits the query defined before. This way, you are able to keep every part of the schema isolated in the apps.</p><p>The following is the schema.py file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0b9904067ea1eb60d304e6f7fe36337/href">https://medium.com/media/b0b9904067ea1eb60d304e6f7fe36337/href</a></iframe><h4>Enable GraphiQL</h4><p><a href="https://github.com/graphql/graphiql">GraphiQl </a>is an interactive web tool that used to test and play with GraphQL.</p><p>To Enable GraphiQL in our project we need to add graphiql url inside url.py file inside graphoracle project</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30ae0ee157bd8171fed7f310edb579b0/href">https://medium.com/media/30ae0ee157bd8171fed7f310edb579b0/href</a></iframe><h3>Query data from Oracle table using GraphQL</h3><p>Finally we can query data from oracle table using GraphQL. We use GraphiQL tool to run query</p><ul><li>Get Employee table data</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nlAYdOlhkpX4TvtifxQ5hQ.png" /></figure><ul><li>Get Employee with department name</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I_usAQzlKITAlk4fNYkv_w.png" /></figure><h3>References</h3><ul><li><a href="https://www.howtographql.com/">How to GraphQL - The Fullstack Tutorial for GraphQL</a></li><li><a href="https://graphql.org/">GraphQL | A query language for your API</a></li><li><a href="https://www.djangoproject.com/">Django</a></li><li><a href="https://www.oracle.com/database/technologies/appdev/xe.html">Oracle Database Express Edition</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c504cc2d343" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/query-oracle-database-data-using-graphql-python-2c504cc2d343">Query ORACLE Database Data Using GraphQL-Python</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Apache Nifi to Load Tweets from Twitter API to MemSQL]]></title>
            <link>https://medium.com/@moha.ajori/using-apache-nifi-to-load-tweets-from-twitter-api-to-memsql-19e19a3be20e?source=rss-e5c9f0ac9d6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/19e19a3be20e</guid>
            <category><![CDATA[memsql]]></category>
            <category><![CDATA[apache-nifi]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[twitter]]></category>
            <category><![CDATA[streaming]]></category>
            <dc:creator><![CDATA[mohammad H. AbdelQader]]></dc:creator>
            <pubDate>Wed, 01 May 2019 09:30:30 GMT</pubDate>
            <atom:updated>2019-05-01T09:30:30.408Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post I will create data flow using <a href="https://nifi.apache.org/">Apache Nifi</a>. This data flow get tweets from twitter and then load to table in <a href="https://www.memsql.com/">MemSQL </a>database.</p><p>So, let’s dig into creating database and table in MemSQL, creating data flow in Apache Nifi, creating Database Connection pooling service in Apache Nifi to connect to MemSQL.</p><h4>Prerequisites</h4><ul><li>MemSQL installed and configured (I used on premise single host)</li><li>Apache Nifi installed and started (I used <a href="https://www.cloudera.com/products/cdf.html">Cloudera flow management</a> Apache Nifi 1.9.0.1 version)</li><li>Twitter account Keys and Token. We can get it from app details when login from <a href="https://developer.twitter.com/">twitter developers site</a></li></ul><h4><strong><em>Steps for creating database and tables in MemSQL</em></strong></h4><ol><li>Run MemSQL command from OS</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*0dU-vYs1iZbOyIogsw9_NQ.png" /></figure><p>2. Check existing databases and create testDB database</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*gdLn-gbbr1LRf662LTUMUw.png" /></figure><p>3. Create tweets_tab table. This table will contain tweet created date, tweet language and tweet text</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*_jArqgWhlspnOPe7AiP6UA.png" /></figure><h4><strong><em>Steps for creating Apache Nifi processor</em></strong></h4><p>We can load processors from Apache Nifi UI through below steps:</p><p>1. Navigate Apache Nifi UI at http://&lt;hostip&gt;:8080/nifi</p><p>2. Drag drop Processor icon to work area</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*XoChIkkrdhGvH0oqeObJ9w.png" /></figure><p>3. Select needed processor then click Add</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*kgAw06meEocsTRCbl6gihw.png" /></figure><p>4. Change processors property by double click on processor then go to properties tab</p><blockquote>The list of processors exists on Apache Nifi site ( <a href="https://nifi.apache.org/docs.html">https://nifi.apache.org/docs.html</a>)</blockquote><p>In Our example we used the following processors:</p><ul><li>GetTwitter</li><li>EvaluateJsonPath</li><li>AttributesToJSON</li><li>ConvertJSONToSQL</li><li>ExecuteSQL</li><li>LogMessage</li></ul><h4><strong><em>Steps to Load and change processors properties</em></strong></h4><ol><li><em>GetTwitter Processor</em>: : This processor used to pull tweets from Twitter streaming API. We need to put Consumer Key, Consumer Secret, Access Token and Access Token Secret which we get from Twitter development site</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*Q0An3NYvtA0G-F_5rNKFPg.png" /></figure><p>2. <em>EvaluateJsonPath processor</em>: This processor used to evaluate JSON expressions that pull from Twitter then assign the result of those expressions to flow-file attributes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*BWe4vpOW-wvLuDdtZoW4CA.png" /></figure><p><strong><em>Relationships</em></strong></p><p>The relationship between GetTwitter processor and EvaluateJsonPath processor is success</p><p>3. <em>AttributesToJSON</em>: This processor will create JSON file for flow-file attributes that created from previous processor</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*8mYrNSCeUXyCECcVMvSftQ.png" /></figure><p><strong><em>Relationships</em></strong></p><p>The relationship between EvaluateJsonPath processor and AttributesToJSON processor is matched relationship. (I choice automatically terminate for failure and unmatched relationship options from EvaluateJsonPath setting)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*UgAalqGU_h75401ju61gaQ.png" /></figure><p>4. <em>ConvertJSONToSQL</em>: This processor converts JSON file to DML statement. To use this processor, we need to create JDBC Connection Pool.</p><p>We will create JDBC Connection Pool that connect to MemSQL database. We create this pool by select “Create New Service” from drop down list on JDBC Connection pool property as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*VUdAbHp_t_WD9X09Jhg7JA.png" /></figure><p>When popup appear, we need to select “DBCPConnectionPool 1.9.0.1.0.0.0–90” and put name for this pool</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*4gFpaI_RWMVLLy4S63UDUQ.png" /></figure><p>After click create button, we need to click on arrow that appear on right and click yes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*kbADVexdOTe1fJjlN1iJGg.png" /></figure><p>Then click on configure icon and configure connection to database</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*PnfSVHdN-GEX1LjFpFwccA.png" /></figure><p>We must have “mysql-connector-java-5.1.47.jar” library and put the path of this jar file in Database Driver Location property</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*6dU2qxGwAr4Vvm25vhKmMA.png" /></figure><p>After click Apply button, we must click Enable icon</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*JSY2kbbZ_29HBhrNGJ6ZiQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*v_8FrE_WPpxBvYM44bHGKQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*j9pZ54INulcbqJowBI30Ag.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*-PHp-yrK0P-KJ3ZoMkYm_A.png" /></figure><p>Now we need to go back to ConvertJSONToSQL processor properties tab and completer another property, we need to select INSERT option for statement type property and put MemSQL table “tweets_tab” in Table Name property</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*g2ogyzl8yGhycFb9O57a4g.png" /></figure><p><strong><em>Relationships</em></strong></p><p>The relationship between AttributesToJSON processor and convertJSONToSQL processor is success relationship (I choice automatically terminate for failure relationship options from AttributesToJSON setting)</p><p>5. <em>ExecuteSQL processor</em>: This processor used to execute insert statement come from ConvertJSONToSQL processor.</p><p>We need to select the same Connection pool that created on ConvertJSONToSQL for Database Connection Pooling Service property</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*TSUWZi7U11X4uHJosiGsBQ.png" /></figure><p><strong><em>Relationships</em></strong></p><p>The relationship between ConvertJSONToSQL processor and ExecuteSQL processor is sql relationship (I choice automatically terminate for original relationship options from ConvertJSONToSQL setting).</p><p>6. <em>LogMessage processor</em>: This processor used to write Log message at specific level</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*mAN8dQAfGhCpYHqFSnvOMg.png" /></figure><p>Finally the processors relations will be like below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0nLdSKbzbFKZVNXaaUgQYg.png" /></figure><h4><strong><em>Steps to Run processors and check data in MemSQL table</em></strong></h4><p>The following video shown the processors configurations and how to start processors then check data in MemSQL table after loaded from Twitter API</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FJnz-a_wCYp4%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DJnz-a_wCYp4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FJnz-a_wCYp4%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/757dd0130b0fb1ab8fd0b149bd7f3516/href">https://medium.com/media/757dd0130b0fb1ab8fd0b149bd7f3516/href</a></iframe><h4>References</h4><ul><li><a href="https://nifi.apache.org/docs.html">https://nifi.apache.org/docs.html</a></li><li><a href="https://www.cloudera.com/products/cdf.html">https://www.cloudera.com/products/cdf.html</a></li><li><a href="https://docs.memsql.com/">https://docs.memsql.com/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19e19a3be20e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PolyBase In Microsoft SQL SERVER]]></title>
            <link>https://medium.com/@moha.ajori/polybase-in-microsoft-sql-server-e32f1972e90e?source=rss-e5c9f0ac9d6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e32f1972e90e</guid>
            <category><![CDATA[polybase]]></category>
            <category><![CDATA[sql-server]]></category>
            <category><![CDATA[hadoop]]></category>
            <category><![CDATA[oracle]]></category>
            <category><![CDATA[big-data]]></category>
            <dc:creator><![CDATA[mohammad H. AbdelQader]]></dc:creator>
            <pubDate>Wed, 17 Oct 2018 09:10:30 GMT</pubDate>
            <atom:updated>2018-10-17T09:10:30.991Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is PolyBase ???</h3><p>PolyBase enables your SQL Server instance to process Transact-SQL queries that read data from external data sources.</p><p>Starting from SQL Server 2019 CTP 2.0, you can use polybase to connect to ORACLE, TERADATA, MONGODB additionally to access external data in Hadoop and Azure Blob Storage which already exists from SQL 2016 and higher.</p><h3>Why use PolyBase?</h3><p>In the past it was more difficult to join your SQL Server data with external data. You had the two following unpleasant options:</p><ul><li>Transfer half your data so that all your data was in one format or the other.</li><li>Query both sources of data, then write custom query logic to join and integrate the data at the client level.</li></ul><p>PolyBase avoids those unpleasant options by using T-SQL to join the data. You query external data by using the same T-SQL syntax used to query a database table. The support actions implemented by PolyBase all happen transparently.</p><h3>How-To-Guides</h3><h4>Install</h4><p>When install SQL server instance, you must select <strong><em>PolyBase Query Service for External Data</em></strong> feature from installation Wizard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*6fPRQjH5k5mF10h9ja4tnQ.png" /><figcaption>Choosing Polybase feature through installation wizard</figcaption></figure><h4>Enable PolyBase</h4><p>I use new tool from Microsoft called “Azure Data Studio” to run required command to enable and configure PolyBase feature. Also you can use SQL Server Management Studio.</p><pre><strong><em>-- Check polybase feature</em></strong></pre><pre>exec sp_configure ‘polybase enabled’</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*kppaNiWyK73R58PbXRCe1A.png" /></figure><pre><strong><em>-- Change polybase value to 1</em></strong></pre><pre>exec sp_configure @configname = ‘polybase enabled’, @configvalue = 1;</pre><pre>RECONFIGURE;<br><strong><em>--Re-check polybase feature</em></strong></pre><pre>exec sp_configure ‘polybase enabled’;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*1fMk_JFa-Bu1vtzPsb4QUQ.png" /></figure><pre>SELECT SERVERPROPERTY (‘IsPolybaseInstalled’) AS IsPolybaseInstalled;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*l1dqczZsWYCwQAg0E13H1A.png" /></figure><p>Then you need to restart SQL Server Services and PolyBase service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*7pOCi-SWWauP3bnc6NpeAA.png" /></figure><h3>Connect To Hadoop Cluster</h3><p>PolyBase supports two Hadoop providers, Hortonworks Data Platform (HDP) and Cloudera Distributed Hadoop (CDH). Hadoop follows the “Major.Minor.Version” pattern for its new releases, and all versions within a supported Major and Minor release are supported. The following Hadoop providers are supported:</p><ul><li>Hortonworks HDP 1.3 on Linux/Windows Server</li><li>Hortonworks HDP 2.1–2.6 on Linux</li><li>Hortonworks HDP 2.1–2.3 on Windows Server</li><li>Cloudera CDH 4.3 on Linux</li><li>Cloudera CDH 5.1–5.5, 5.9–5.13 on Linux</li></ul><p>The following demo explains how to use PolyBase on a SQL Server instance to query external data in Hadoop (Hortonworks HDP 3.0 on Linux).</p><p><strong><em>Configuration Settings</em></strong></p><pre><strong><em>-- Check Hadoop Connectivity Setting</em></strong><br>exec sp_configure ‘hadoop connectivity’</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*J9sIDgckQ3h16TCLLo_mmQ.png" /></figure><pre><strong><em>-- Enable Hadoop Connectivity</em></strong><br>exec sp_configure @configname = ‘hadoop connectivity’, @configvalue = 7;</pre><pre>RECONFIGURE;</pre><pre><strong><em>-- Re-Check Hadoop Connectivity</em></strong> <br>exec sp_configure ‘hadoop connectivity’</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*z56ac0pVObJYqy8ckfcAaA.png" /></figure><p>To improve query performance , you can enable pushdown computation to you Hadoop Cluster by :</p><ol><li>Find yarn-site.xml file ( exist on C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\Binn\Polybase\Hadoop\conf)</li><li>On the Hadoop machine, find the analogous file in the Hadoop configuration directory. In the file, find and copy the value of the configuration key <strong><em>yarn.application.classpath</em></strong></li><li>On the SQL Server machine, in the <strong><em>yarn.site.xml</em></strong> file, find the <strong><em>yarn.application.classpath</em></strong> property. Paste the value from the Hadoop machine into the value element. ( Following Example)</li></ol><pre>&lt;name&gt;yarn.application.classpath&lt;/name&gt;&lt;value&gt;$HADOOP_CONF_DIR,/usr/hdp/3.0.1.0–187/hadoop/*,/usr/hdp/3.0.1.0–187/hadoop/lib/*,/usr/hdp/current/hadoop-hdfs-client/*,/usr/hdp/current/hadoop-hdfs-client/lib/*,/usr/hdp/current/hadoop-yarn-client/*,/usr/hdp/current/hadoop-yarn-client/lib/*&lt;/value&gt;</pre><p>Then you need to restart SQL Server Services and PolyBase service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*7pOCi-SWWauP3bnc6NpeAA.png" /></figure><p><strong><em>Configure an External Table</em></strong></p><pre><strong><em>-- Create master key for database</em></strong></pre><pre>CREATE MASTER KEY ENCRYPTION BY PASSWORD = ‘Polybase!2018’;</pre><pre><strong><em>--</em></strong> <strong><em>Create scoped credential</em></strong></pre><pre>CREATE DATABASE SCOPED CREDENTIAL hdfsUser WITH IDENTITY = ‘hdfs’, Secret = ‘&lt;PASSWORD&gt;’;</pre><pre><strong><em>-- Create external source for hortonworks HDP cluster<br>-- LOCATION (Required) : Hadoop Name Node IP address and port.  <br>-- RESOURCE MANAGER LOCATION (Optional): Hadoop Resource Manager location to enable pushdown computation.   <br>-- CREDENTIAL (Optional):  the database scoped credential, created above.</em></strong></pre><pre>CREATE EXTERNAL DATA SOURCE HDPCluster WITH (</pre><pre>TYPE = HADOOP,</pre><pre>LOCATION =&#39;hdfs://192.168.xx.xx:8020&#39;,</pre><pre>RESOURCE_MANAGER_LOCATION = &#39;192.168.x.xx:8050&#39;,</pre><pre>CREDENTIAL = hdfsUser</pre><pre>);</pre><pre><strong><em>-- Create external format <br></em>-- FORMAT TYPE: Type of format in Hadoop (DELIMITEDTEXT,  RCFILE, ORC, PARQUET).</strong></pre><pre>CREATE EXTERNAL FILE FORMAT TextPipeFileFormat WITH (</pre><pre>FORMAT_TYPE = DELIMITEDTEXT,</pre><pre>FORMAT_OPTIONS (FIELD_TERMINATOR =&#39;|&#39;,</pre><pre>USE_TYPE_DEFAULT = TRUE) );</pre><pre><strong><em>-- Create schema for Hadoop tables</em></strong><br>CREATE SCHEMA hadoop;</pre><pre><strong><em>-- Create external table for hadoop<br>-- LOCATION: path to file or directory that contains the data (relative to HDFS root).</em></strong></pre><pre>Create EXTERNAL TABLE hadoop.employees (</pre><pre>id bigint ,</pre><pre>name varchar(200) COLLATE Arabic_BIN,</pre><pre>salary bigint )</pre><pre>WITH (LOCATION=&#39;/user/hdfs/employee.csv&#39;,</pre><pre>DATA_SOURCE = HDPCluster,</pre><pre>FILE_FORMAT = TextPipeFileFormat</pre><pre>);</pre><pre><strong><em>-- Create statistics for external table</em></strong><br>CREATE STATISTICS empstats on hadoop.employees(id, salary)</pre><pre><strong><em>-- select data from hadoop table</em></strong></pre><pre>select * from hadoop.employees;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_5jEkLB5DjYnVeolb9220Q.png" /><figcaption>List data from SQL Server</figcaption></figure><p>checking the data inside Hadoop file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QQj1CJwrAvgVxEuF9A93hQ.png" /><figcaption>List data from HDFS file</figcaption></figure><h3>Connect To ORACLE database</h3><p>The following demo explains how to use PolyBase on a SQL Server instance to query external data in ORACLE database instance (12cR2 on Linux)</p><pre><strong><em>-- Create master key for database (If you didn&#39;t create it before)</em></strong></pre><pre>CREATE MASTER KEY ENCRYPTION BY PASSWORD = ‘Polybase!2018’;<br><strong><em>-- Create scoped credential</em></strong></pre><pre>CREATE DATABASE SCOPED CREDENTIAL OracleUser  WITH IDENTITY = &#39;hr&#39;, Secret = &#39;&lt;PASSWORD&gt;&#39;;</pre><pre><strong><em>-- create external data source for oracle<br>-- LOCATION: Location string should be of format <br>--&#39;&lt;vendor&gt;://&lt;server&gt;[:&lt;port&gt;]&#39;. *  <br>--PUSHDOWN: specify whether computation should be pushed down to the -- source. ON by default. *  CREDENTIAL: the database scoped<br>-- credential, created above.</em></strong></pre><pre>CREATE EXTERNAL DATA SOURCE [OracleDB]  WITH (<br>LOCATION = &#39;oracle://192.168.xx.xx&#39;,<br>CREDENTIAL = OracleUser<br>);</pre><pre><strong><em>-- Create schema for oracle</em></strong></pre><pre>CREATE SCHEMA oracle;</pre><pre><strong><em>-- Create external table for oracle<br>-- LOCATION: Oracle table/view in &#39;&lt;database_name&gt;.&lt;schema_name&gt;.&lt;object_name&gt;&#39; format (MUST BE CAPITAL LETTER)<br>-- DATA_SOURCE: the external data source, created above.</em></strong></pre><pre>CREATE EXTERNAL TABLE oracle.employees(<br>id DECIMAL(6),<br>name VARCHAR(100) COLLATE Arabic_BIN,<br>salary decimal(8)<br>)<br>WITH (<br>LOCATION=&#39;ORCL12C.HR.EMPLOYEE_HISTORY&#39;,<br>DATA_SOURCE=OracleDB<br>);</pre><pre><strong><em>-- Create stats for oracle table</em></strong></pre><pre>CREATE STATISTICS empstatsOracle ON oracle.employees(id) WITH FULLSCAN;</pre><pre>-- Select data from external table</pre><pre>select * from oracle.employees</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/1*Q_BIqLTAIj1mhBeIVLJ28Q.png" /></figure><p>Get data from Hadoop file and ORACLE table thorough PolyBase</p><pre>select * from (</pre><pre>select * from oracle.employees</pre><pre>union all</pre><pre>select * from hadoop.employees</pre><pre>) x order by id asc</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*k0Yn0tle1btAP36zyl7pwQ.png" /></figure><h3><strong><em>REFERENCES</em></strong></h3><p><a href="https://docs.microsoft.com/en-us/sql/relational-databases/polybase/polybase-guide?view=sql-server-ver15">Introducing data virtualization with PolyBase - SQL Server</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e32f1972e90e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Oracle SQL Connector for Hadoop HDFS]]></title>
            <link>https://medium.com/@moha.ajori/oracle-sql-connector-for-hadoop-hdfs-ca53df27c741?source=rss-e5c9f0ac9d6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca53df27c741</guid>
            <category><![CDATA[hortonworks]]></category>
            <category><![CDATA[oracle-database]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[oracle]]></category>
            <category><![CDATA[hadoop]]></category>
            <dc:creator><![CDATA[mohammad H. AbdelQader]]></dc:creator>
            <pubDate>Thu, 19 Jul 2018 13:05:39 GMT</pubDate>
            <atom:updated>2018-07-19T13:09:57.999Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article I will use Oracle SQL Connector to access data from HDFS file.</p><p>Oracle SQL Connector for HDFS uses external tables to provide Oracle Database with read access to Hive tables, and to delimited text files and Data Pump files in HDFS</p><p>An <strong>external table</strong> is an Oracle Database object that identifies the location of data outside of a database. Oracle Database accesses the data by using the metadata provided when the external table was created. By querying the external tables, you can access data stored in HDFS and Hive tables as if that data were stored in tables in an Oracle database.</p><p>We will use <strong>ExternalTable</strong> command-line provided with Oracle SQL connector for HDFS.</p><p>When external table is ready, we can query the data from table or join data in HDFS or Hive table with other database resident data.</p><p>In My demo the Oracle database version is 12.2.0. For Hadoop Distributed File system, I using Hortonworks HDP version 2.6</p><p>Article Contents:</p><ol><li>Installing Hadoop client in Oracle database server</li><li>Downloading and Configure oracle SQL Connector for HDFS</li><li>Creating required database objects ( directories and user )</li><li>Creating external table using ExternalTable command-line</li></ol><blockquote>Installing Hadoop client in Oracle database server</blockquote><blockquote>Get latest yum repository for Hortonworks</blockquote><pre>[root@apex ~]$ wget <a href="http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.6.3.0/hdp.repo">http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.6.3.0/hdp.repo</a><br>[root@apex ~]$ mv hdp.repo /etc/yum.repos.d/</pre><blockquote>Install Hadoop client using yum</blockquote><pre>[root@apex ~]$ yum install hadoop pig hive-hcatalog hive-webhcat tez hdfs hadoop-client<br>...</pre><pre>[root@apex ~]$ which hadoop<br>/usr/bin/hadoop</pre><blockquote>Get hadoop configuration file from Hadoop cluster (command must run in hadoop cluster node )</blockquote><pre>[hdfs@HDP-node1 ~]$ scp /etc/hadoop/2.6.3.0-235/0/core-site.xml root@&lt;oracle DB IP Address&gt;:/etc/hadoop/conf/</pre><pre>[hdfs@HDP-node1 ~]$ scp /etc/hadoop/2.6.3.0-235/0/hdfs-site.xml root@&lt;oracle DB IP Address&gt;:/etc/hadoop/conf/</pre><p><strong><em>Note: we need to add hostname of Hadoop node in /etc/hosts file</em></strong></p><blockquote>Export variables and put it in .bash_profile</blockquote><pre>[oracle@apex ~]$ export JAVA_HOME=/usr/jdk1.8.0_112/</pre><pre>[oracle@apex ~]$ export HADOOP_CONF_DIR=/etc/hadoop/conf</pre><blockquote>Test Hadoop client</blockquote><pre>[oracle@apex ~]$ hadoop fs -ls /user<br>Found 12 items<br>drwxr-xr-x   - hdfs      hdfs            0 2018-02-05 13:31 /user/admin<br>drwxrwx---   - ambari-qa hdfs            0 2018-02-07 08:10 /user/ambari-qa<br>drwxr-xr-x   - druid     hadoop          0 2018-03-12 11:34 /user/druid<br>drwxr-xr-x   - hcat      hdfs            0 2018-02-05 09:13 /user/hcat<br>drwxr-xr-x   - hdfs      hdfs            0 2018-07-18 08:56 /user/hdfs<br>drwxr-xr-x   - hdfs      hdfs            0 2018-02-06 16:43 /user/hdp<br>drwxr-xr-x   - hdfs      hdfs            0 2018-02-13 10:25 /user/history<br>drwxr-xr-x   - hive      hdfs            0 2018-02-27 17:28 /user/hive<br>drwxrwxr-x   - oozie     hdfs            0 2018-02-07 08:02 /user/oozie<br>drwxrwxr-x   - spark     hdfs            0 2018-02-25 15:28 /user/spark<br>drwxr-xr-x   - hdfs      hdfs            0 2018-02-06 12:54 /user/sqoobStaging<br>drwxr-xr-x   - zeppelin  hdfs            0 2018-02-21 13:18 /user/zeppelin</pre><blockquote>Downloading and Configure oracle SQL Connector for HDFS</blockquote><p>We can download Oracle SQL connector for HDFS from Oracle site link( <a href="http://www.oracle.com/technetwork/database/database-technologies/bdc/big-data-connectors/downloads/index.html">http://www.oracle.com/technetwork/database/database-technologies/bdc/big-data-connectors/downloads/index.html</a>)</p><blockquote>Install and configure Oracle SQL Connector for HDFS</blockquote><pre>[oracle@apex ~]$ unzip orahdfs-3.8.0.zip<br>Archive:  orahdfs-3.8.0.zip<br>   creating: orahdfs-3.8.0/<br>   creating: orahdfs-3.8.0/bin/<br>  inflating: orahdfs-3.8.0/bin/hdfs_stream<br>  inflating: orahdfs-3.8.0/bin/hdfs_stream.cmd<br>   creating: orahdfs-3.8.0/examples/<br>   creating: orahdfs-3.8.0/examples/sql/<br>  inflating: orahdfs-3.8.0/examples/sql/mkhive_unionall_view.sql<br>   creating: orahdfs-3.8.0/log/<br>   creating: orahdfs-3.8.0/doc/<br>  inflating: orahdfs-3.8.0/doc/README.txt<br>   creating: orahdfs-3.8.0/jlib/<br>  inflating: orahdfs-3.8.0/jlib/osdt_core.jar<br>  inflating: orahdfs-3.8.0/jlib/oraclepki.jar<br>  inflating: orahdfs-3.8.0/jlib/osdt_cert.jar<br>  inflating: orahdfs-3.8.0/jlib/oraloader.jar<br>  inflating: orahdfs-3.8.0/jlib/ojdbc7.jar<br>  inflating: orahdfs-3.8.0/jlib/ora-hadoop-common.jar<br>  inflating: orahdfs-3.8.0/jlib/orai18n.jar<br>  inflating: orahdfs-3.8.0/jlib/orahdfs.jar</pre><blockquote>Edit hdfs_stream file</blockquote><pre>[oracle@apex orahdfs-3.8.0]$ cd bin/<br>[oracle@apex bin]$ vi hdfs_stream</pre><pre>#Uncomment and Add below variables:</pre><pre>export JAVA_HOME=/usr/jdk1.8.0_112<br>export HADOOP_CONF_DIR=/etc/hadoop/conf<br>OSCH_LOG_DIR=/home/oracle/orahdfs-3.8.0/log</pre><blockquote>Export Oracle SQL Connector variables and put it in .bash_profile</blockquote><pre>[oracle@apex bin]$ export OSCH_BIN_PATH=/home/oracle/orahdfs-3.8.0/bin<br>[oracle@apex bin]$ export HADOOP_CLASSPATH=/home/oracle/orahdfs-3.8.0/jlib/*:$HADOOP_CLASSPATH<br>[oracle@apex bin]$ export OSCH_HOME=/home/oracle/orahdfs-3.8.0</pre><blockquote>Testing Oracle SQL Connector to HDFS connectivity</blockquote><pre>[oracle@apex bin]$ ./hdfs_stream<br>Usage 1: hdfs_stream locationFile<br>Usage 2: export HDFS_STREAM_DEBUG=1; hdfs_stream hdfsDirectory</pre><blockquote>Creating required database objects ( directories and user )</blockquote><blockquote>Creating user and give him required privileges</blockquote><pre>SQL&gt; create user hdfsuser identified by hdfs;</pre><pre>User created.</pre><pre>SQL&gt; grant create session,create table,create view to hdfsuser;</pre><pre>Grant succeeded.</pre><pre>SQL&gt; grant execute on sys.utl_file to hdfsuser;</pre><pre>Grant succeeded.</pre><blockquote>Creating required directories</blockquote><pre>SQL&gt; create directory osch_bin_path as &#39;/home/oracle/orahdfs-3.8.0/bin&#39;;</pre><pre>SQL&gt; grant read,execute on directory osch_bin_path to hdfsuser;</pre><pre>Grant succeeded.</pre><pre>SQL&gt; create directory external_table_dir as &#39;/home/oracle/externalTable&#39;;</pre><pre>Directory created.</pre><pre>SQL&gt; GRANT READ, WRITE ON DIRECTORY external_table_dir TO hdfsuser;</pre><pre>Grant succeeded.</pre><pre>SQL&gt; exit</pre><blockquote>Creating external table using ExternalTable command-line</blockquote><blockquote>Listing HDFS file from Hadoop server which contain data</blockquote><pre>[oracle@apex bin]$ hadoop fs -ls /user/hdfs/retail-data/all<br>Found 1 items<br>-rwxr-xr-x 3 hdfs hdfs 45038760 2018–06–27 11:42 /user/hdfs/retail-data/all/online-retail-dataset.csv<br>[oracle@apex bin]$</pre><blockquote>Creating External Table</blockquote><pre>[oracle@apex bin]$ hadoop jar $OSCH_HOME/jlib/orahdfs.jar oracle.hadoop.exttab.ExternalTable -D oracle.hadoop.exttab.tableName=&quot;retail_data&quot;  -D oracle.hadoop.exttab.dataPaths=&quot;hdfs://&lt;Hadoop Name Node IP&gt;:8020/user/hdfs/retail-data/all/online-retail-dataset.csv&quot; -D oracle.hadoop.exttab.columnCount=8 -D oracle.hadoop.exttab.defaultDirectory=&quot;EXTERNAL_TABLE_DIR&quot; -D oracle.hadoop.connection.url=&quot;jdbc:oracle:thin:@//&lt;Database server IP&gt;:1521/hdppdb&quot; -D oracle.hadoop.connection.user=&quot;hdfsuser&quot; -createTable<br>Oracle SQL Connector for HDFS Release 3.8.0 - Production</pre><pre>Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.</pre><pre>[Enter Database Password:]<br>The create table command succeeded.</pre><pre>User: &quot;HDFSUSER&quot; performed the following actions in schema: HDFSUSER</pre><pre>CREATE TABLE &quot;HDFSUSER&quot;.&quot;RETAIL_DATA&quot;<br>(<br> &quot;C1&quot;                             VARCHAR2(4000),<br> &quot;C2&quot;                             VARCHAR2(4000),<br> &quot;C3&quot;                             VARCHAR2(4000),<br> &quot;C4&quot;                             VARCHAR2(4000),<br> &quot;C5&quot;                             VARCHAR2(4000),<br> &quot;C6&quot;                             VARCHAR2(4000),<br> &quot;C7&quot;                             VARCHAR2(4000),<br> &quot;C8&quot;                             VARCHAR2(4000)<br>)<br>ORGANIZATION EXTERNAL<br>(<br>   TYPE ORACLE_LOADER<br>   DEFAULT DIRECTORY &quot;EXTERNAL_TABLE_DIR&quot;<br>   ACCESS PARAMETERS<br>   (<br>     RECORDS DELIMITED BY 0X&#39;0A&#39;<br>     CHARACTERSET AL32UTF8<br>     PREPROCESSOR &quot;OSCH_BIN_PATH&quot;:&#39;hdfs_stream&#39;<br>     FIELDS TERMINATED BY 0X&#39;2C&#39;<br>     MISSING FIELD VALUES ARE NULL<br>     (<br>       &quot;C1&quot; CHAR(4000),<br>       &quot;C2&quot; CHAR(4000),<br>       &quot;C3&quot; CHAR(4000),<br>       &quot;C4&quot; CHAR(4000),<br>       &quot;C5&quot; CHAR(4000),<br>       &quot;C6&quot; CHAR(4000),<br>       &quot;C7&quot; CHAR(4000),<br>       &quot;C8&quot; CHAR(4000)<br>     )<br>   )<br>   LOCATION<br>   (<br>     &#39;osch-7155E9633B480DD1E0536B02A8C0812A-1-1&#39;<br>   )<br>) PARALLEL REJECT LIMIT UNLIMITED;</pre><pre>The following location files were created.</pre><pre>osch-7155E9633B480DD1E0536B02A8C0812A-1-1 contains 1 URI, 45038760 bytes</pre><pre>45038760 hdfs://&lt;Hadoop Name Node IP&gt;:8020/user/hdfs/retail-data/all/online-retail-dataset.csv</pre><pre>[oracle@apex bin]$</pre><p><strong><em>Note: we can use parameter oracle.hadoop.exttab.columnNames to provide column names rather than C1,C2… names</em></strong></p><blockquote>Publishing External Table</blockquote><pre>[oracle@apex bin]$ hadoop jar $OSCH_HOME/jlib/orahdfs.jar oracle.hadoop.exttab.ExternalTable -D oracle.hadoop.exttab.tableName=&quot;retail_data&quot;  -D oracle.hadoop.exttab.dataPaths=&quot;hdfs://&lt;Hadoop Name Node port&gt;:8020/user/hdfs/retail-data/all/online-retail-dataset.csv&quot; -D oracle.hadoop.exttab.defaultDirectory=&quot;EXTERNAL_TABLE_DIR&quot; -D oracle.hadoop.connection.url=&quot;jdbc:oracle:thin:@//&lt;Oracle databae server IP&gt;:1521/hdppdb&quot; -D oracle.hadoop.connection.user=&quot;hdfsuser&quot; -publish<br>Oracle SQL Connector for HDFS Release 3.8.0 - Production</pre><pre>Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.</pre><pre>[Enter Database Password:]<br>The publish command was executed.</pre><pre>The following tables were altered.</pre><pre>ALTER TABLE &quot;HDFSUSER&quot;.&quot;RETAIL_DATA&quot;<br>LOCATION<br>(<br>  &#39;osch-7155F1BC83600E0BE0536B02A8C097AC-1-1&#39;<br>);</pre><pre>The following location files were created.</pre><pre>osch-7155F1BC83600E0BE0536B02A8C097AC-1-1 contains 1 URI, 45038760 bytes</pre><pre>45038760 hdfs://&lt;Hadoop Name Node IP&gt;:8020/user/hdfs/retail-data/all/online-retail-dataset.csv</pre><pre>The following location files were deleted.</pre><pre>osch-7155E9633B480DD1E0536B02A8C0812A-1-1 was deleted.<br>[oracle@apex bin]$</pre><blockquote>Checking table data from SQLPLUS</blockquote><pre>[oracle@apex bin]$ sqlplus hdfsuser/hdfs@hdppdb</pre><pre>SQL*Plus: Release 12.2.0.1.0 Production on Thu Jul 19 10:16:13 2018</pre><pre>Copyright (c) 1982, 2016, Oracle.  All rights reserved.</pre><pre>Last Successful login time: Thu Jul 19 2018 10:15:30 +03:00</pre><pre>Connected to:<br>Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production</pre><pre>SQL&gt; select count(*) from retail_data;</pre><pre>COUNT(*)<br>----------<br>    541910</pre><pre>SQL&gt;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca53df27c741" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>