![]() |
VOOZH | about |
Apache Airflow supports the creation, scheduling, and monitoring of data engineering workflows. When paired with the CData JDBC Driver for Dynamics NAV, Airflow can work with live Dynamics NAV data. This article describes how to connect to and query Dynamics NAV data from an Apache Airflow instance and store the results in a CSV file.
With built-in optimized data processing, the CData JDBC driver offers unmatched performance for interacting with live Dynamics NAV data. When you issue complex SQL queries to Dynamics NAV, the driver pushes supported SQL operations, like filters and aggregations, directly to Dynamics NAV and utilizes the embedded SQL engine to process unsupported operations client-side (often SQL functions and JOIN operations). Its built-in dynamic metadata querying allows you to work with and analyze Dynamics NAV data using native data types.
For assistance in constructing the JDBC URL, use the connection string designer built into the Dynamics NAV JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.
java -jar cdata.jdbc.dynamicsnav.jar
Fill in the connection properties and copy the connection string to the clipboard.
Before you can connect, OData Services will need to be enabled on the server. Once OData Services are enabled, you will be able to query any Services that are published on the server.
The User and Password properties, under the Authentication section, must be set to valid Dynamics NAV user credentials. In addition, specify a URL to a valid Dynamics NAV server organization root and a ServerInstance. If there is not a Service Default Company for the server, set the Company as well.
π Using the built-in connection string designer to generate a JDBC URL (dynamics nav is shown.)To host the JDBC driver in clustered environments or in the cloud, you will need a license (full or trial) and a Runtime Key (RTK). For more information on obtaining this license (or a trial), contact our sales team.
The following are essential properties needed for our JDBC connection.
| Property | Value |
|---|---|
| Database Connection URL | jdbc:dynamicsnav:RTK=5246...;http://myserver:7048;User=myserver\Administrator;Password=admin;ServerInstance=DYNAMICSNAV71; |
| Database Driver Class Name | cdata.jdbc.dynamicsnav.DynamicsNAVDriver |
A DAG in Airflow is an entity that stores the processes for a workflow and can be triggered to run this workflow. Our workflow is to simply run a SQL query against Dynamics NAV data and store the results in a CSV file.
import time
from datetime import datetime
from airflow.decorators import dag, task
from airflow.providers.jdbc.hooks.jdbc import JdbcHook
import pandas as pd
# Declare Dag
@dag(dag_id="dynamics nav_hook", schedule_interval="0 10 * * *", start_date=datetime(2022,2,15), catchup=False, tags=['load_csv'])
# Define Dag Function
def extract_and_load():
# Define tasks
@task()
def jdbc_extract():
try:
hook = JdbcHook(jdbc_conn_id="jdbc")
sql = """ select * from Account """
df = hook.get_pandas_df(sql)
df.to_csv("/{some_file_path}/{name_of_csv}.csv",header=False, index=False, quoting=1)
# print(df.head())
print(df)
tbl_dict = df.to_dict('dict')
return tbl_dict
except Exception as e:
print("Data extract error: " + str(e))
jdbc_extract()
sf_extract_and_load = extract_and_load()
Download a free trial of the Dynamics NAV Driver to get started:
Download NowLearn more:
π Dynamics NAV IconRapidly create and deploy powerful Java applications that integrate with Dynamics NAV account data including Items, Sales Orders, Purchase Orders, and more!