How to Configure Microsoft SQL Server PolyBase to Query External Hadoop HDFS Clusters using Transact-SQL

Modern enterprise data architecture is rarely homogeneous. Critical transactional data resides in highly structured Microsoft SQL Server relational databases, while massive volumes of unstructured or semi-structured telemetry, logs, and archival data are dumped into scalable Apache Hadoop Distributed File System (HDFS) clusters. Historically, joining these two datasets required complex Extract, Transform, Load (ETL) pipelines—pulling data out of Hadoop, transforming it, and loading it into SQL Server before analysis could begin. Microsoft SQL Server PolyBase eliminates this bottleneck. By configuring PolyBase, database administrators can write standard Transact-SQL (T-SQL) queries that seamlessly reach out and query external HDFS clusters in real-time, executing the join logic directly within the database engine.

The Architecture of PolyBase

PolyBase acts as a bridge between the SQL Server relational engine and external Big Data systems. When a user submits a T-SQL query that references an External Table (a table whose schema is defined in SQL Server but whose actual data resides in HDFS), the PolyBase engine intercepts the query. It intelligently parses the query execution plan and, when possible, pushes the computational workload down into the Hadoop cluster itself (via MapReduce). Only the resulting, aggregated dataset is returned over the network to SQL Server. This “predicate pushdown” drastically reduces network bandwidth consumption and leverages the massive parallel processing power of the Hadoop cluster.

Enabling the PolyBase Feature

PolyBase is an optional component of SQL Server. If it was not selected during the initial installation, you must rerun the SQL Server setup media, select “Add features to an existing instance,” and check the box for PolyBase Query Service for External Data. Following installation, ensure the SQL Server PolyBase Engine and SQL Server PolyBase Data Movement Windows services are running.

You must also enable the feature at the server configuration level. Open SQL Server Management Studio (SSMS) and execute:

EXEC sp_configure @configname = 'polybase enabled', @configvalue = 1;
RECONFIGURE;

Configuring the External Data Source

To allow SQL Server to communicate with Hadoop, you must define the connection string. This requires establishing a master key for encryption, creating a database-scoped credential (if your Hadoop cluster requires Kerberos or basic authentication), and finally, defining the External Data Source.

-- 1. Create a Master Key (if one doesn't exist)
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'ComplexPassword123!';

-- 2. Define the Hadoop Cluster Connection
CREATE EXTERNAL DATA SOURCE HadoopCluster
WITH (
    TYPE = HADOOP,
    LOCATION = 'hdfs://10.0.0.50:8020'
);

The LOCATION parameter specifies the IP address and RPC port of your Hadoop NameNode.

Defining External File Formats and Tables

SQL Server needs to know how to parse the files sitting in HDFS. Are they comma-separated values (CSV)? Are they snappy-compressed Parquet files? You define this using an External File Format.

CREATE EXTERNAL FILE FORMAT CsvFormat
WITH (
    FORMAT_TYPE = DELIMITEDTEXT,
    FORMAT_OPTIONS (
        FIELD_TERMINATOR = ',',
        USE_TYPE_DEFAULT = TRUE
    )
);

Finally, you map a specific HDFS directory to a SQL Server table schema. This is known as creating an External Table. The syntax is identical to creating a standard table, but you specify the data source and file format.

CREATE EXTERNAL TABLE SensorTelemetry (
    [SensorID] INT NOT NULL,
    [Timestamp] DATETIME2 NOT NULL,
    [Temperature] FLOAT NOT NULL,
    [Humidity] FLOAT NOT NULL
)
WITH (
    LOCATION = '/data/telemetry/2026/',
    DATA_SOURCE = HadoopCluster,
    FILE_FORMAT = CsvFormat
);

Executing the Federated Query

Once the External Table is defined, data analysts can query it exactly as if it were a local table stored on the SQL Server’s physical disks. More importantly, they can join it against local relational data.

SELECT 
    c.CustomerName,
    c.FacilityLocation,
    AVG(s.Temperature) AS AverageTemp
FROM LocalCustomerData c
INNER JOIN SensorTelemetry s ON c.FacilityID = s.SensorID
WHERE s.Timestamp > '2026-01-01'
GROUP BY c.CustomerName, c.FacilityLocation;

In this scenario, PolyBase instructs Hadoop to filter the massive telemetry logs for dates after January 1st, 2026 (predicate pushdown), calculates the averages, and returns only that summarized data to SQL Server, which then joins it against the local customer database. This enables true hybrid data querying without the complexity of maintaining separate ETL infrastructure.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.