Sdílet prostřednictvím


Minimize SQL issues for Teradata migrations

This article is part five of a seven-part series that provides guidance on how to migrate from Teradata to Azure Synapse Analytics. Tento článek se zaměřuje na osvědčené postupy pro minimalizaci problémů s SQL.

Přehled

Characteristics of Teradata environments

Návod

Teradata pioneered large scale SQL databases using MPP in the 1980s.

In 1984, Teradata initially released their database product. It introduced massively parallel processing (MPP) techniques to enable data processing at a scale more efficiently than the existing mainframe technologies available at the time. Od té doby se produkt vyvinul a má mnoho instalací mezi velkými finančními institucemi, telekomunikačními a maloobchodními společnostmi. The original implementation used proprietary hardware and was channel attached to mainframes—typically IBM or IBM-compatible processors.

While more recent announcements have included network connectivity and the availability of the Teradata technology stack in the cloud (including Azure), most existing installations are on premises, so many users are considering migrating some or all their Teradata data to Azure Synapse Analytics to gain the benefits of a move to a modern cloud environment.

Návod

Many existing Teradata installations are data warehouses using a dimensional data model.

Teradata technology is often used to implement a data warehouse, supporting complex analytic queries on large data volumes using SQL. Dimenzionální datové modely – hvězdicová nebo sněhová vločková schémata – jsou běžné, stejně jako implementace datových martů pro jednotlivá oddělení.

Tato kombinace modelů SQL a dimenzionálních dat zjednodušuje migraci do Azure Synapse, protože základní koncepty a dovednosti SQL jsou přenositelné. Doporučeným přístupem je migrace stávajícího datového modelu as-is, aby se snížilo riziko a doba trvání. I když je konečným záměrem provést změny datového modelu (například přechod na model trezoru dat), proveďte počáteční as-is migraci a pak proveďte změny v cloudovém prostředí Azure, využijte výkon, elastickou škálovatelnost a výhody nákladů.

Zatímco jazyk SQL je standardizovaný, jednotliví dodavatelé v některých případech implementovali proprietární rozšíření. This document highlights potential SQL differences you may encounter while migrating from a legacy Teradata environment, and provides workarounds.

Použití instance Teradata virtuálního počítače Azure v rámci migrace

Návod

Use an Azure VM to create a temporary Teradata instance to speed up migration and minimize impact on the source system.

Leverage the Azure environment when running a migration from an on-premises Teradata environment. Azure provides affordable cloud storage and elastic scalability to create a Teradata instance within a VM in Azure, collocated with the target Azure Synapse environment.

With this approach, standard Teradata utilities such as Teradata Parallel Data Transporter (or third-party data replication tools such as Attunity Replicate) can be used to efficiently move the subset of Teradata tables that are to be migrated onto the VM instance, and then all migration tasks can take place within the Azure environment. Tento přístup má několik výhod:

  • After the initial replication of data, the source system isn't impacted by the migration tasks.

  • The familiar Teradata interfaces, tools, and utilities are available within the Azure environment.

  • Once in the Azure environment there are no potential issues with network bandwidth availability between the on-premises source system and the cloud target system.

  • Tools such as Azure Data Factory can efficiently call utilities such as Teradata Parallel Transporter to migrate data quickly and easily.

  • Proces migrace se orchestruje a řídí zcela v rámci prostředí Azure.

Použití služby Azure Data Factory k implementaci migrace řízené metadaty

Návod

Automatizujte proces migrace pomocí funkcí služby Azure Data Factory.

Automatizujte a orchestrujte proces migrace pomocí funkcí v prostředí Azure. This approach also minimizes the migration's impact on the existing Teradata environment, which may already be running close to full capacity.

Azure Data Factory je cloudová služba pro integraci dat, která umožňuje vytvářet pracovní postupy řízené daty v cloudu pro orchestraci a automatizaci přesunu a transformace dat. Pomocí služby Data Factory můžete vytvářet a plánovat pracovní postupy řízené daty ( označované jako kanály), které ingestují data z různorodých úložišť dat. Může zpracovávat a transformovat data pomocí výpočetních služeb, jako jsou Azure HDInsight Hadoop, Spark, Azure Data Lake Analytics a Azure Machine Learning.

Vytvořením metadat pro výpis tabulek dat, které se mají migrovat, a jejich umístěním můžete pomocí zařízení Data Factory spravovat a automatizovat části procesu migrace. Můžete také použít kanály Azure Synapse.

SQL DDL differences between Teradata and Azure Synapse

DDL (SQL Data Definition Language)

Návod

Příkazy CREATE TABLE DDL SQL a CREATE VIEW mají standardní základní prvky, ale slouží také k definování možností specifických pro implementaci.

Standard ANSI SQL definuje základní syntaxi pro příkazy DDL, například CREATE TABLE a CREATE VIEW. These commands are used within both Teradata and Azure Synapse, but they've also been extended to allow definition of implementation-specific features such as indexing, table distribution, and partitioning options.

The following sections discuss Teradata-specific options to consider during a migration to Azure Synapse.

Úvahy o tabulkách

Návod

Pomocí existujících indexů můžete indikovat kandidáty na indexování v migrovaném skladu.

Při migraci tabulek mezi různými technologiemi se mezi těmito dvěma prostředími fyzicky přesunou pouze nezpracovaná data a jejich popisná metadata. Jiné databázové prvky ze zdrojového systému, jako jsou indexy a soubory protokolů, se nemigrují přímo, protože tyto prvky nemusí být potřeba nebo se můžou implementovat jinak v novém cílovém prostředí. For example, there's no equivalent of the MULTISET option within Teradata's CREATE TABLE syntax.

Je důležité pochopit, kde se ve zdrojovém prostředí používaly optimalizace výkonu , například indexy. Označuje, kde je možné do nového cílového prostředí přidat optimalizaci výkonu. For example, if a non-unique secondary index (NUSI) has been created in the source Teradata environment, this might indicate that a non-clustered index should be created in the migrated Azure Synapse database. Jiné nativní techniky optimalizace výkonu, jako je například replikace tabulek, mohou být vhodnější než přímé vytvoření indexu like-for-like.

Nepodporované typy tabulek Teradata

Návod

Standard tables within Azure Synapse can support migrated Teradata time-series and temporal tables.

Teradata includes support for special table types for time-series and temporal data. The syntax and some of the functions for these table types aren't directly supported within Azure Synapse, but the data can be migrated into a standard table with appropriate data types and indexing or partitioning on the date/time column.

Teradata implements the temporal query functionality via query rewriting to add additional filters within a temporal query to limit the applicable date range. If this functionality is currently in use within the source Teradata environment and is to be migrated, then this additional filtering will need to be added into the relevant temporal queries.

The Azure environment also includes specific features for complex analytics on time-series data at scale called time series insights—this is aimed at IoT data analysis applications and may be more appropriate for this use-case.

Unsupported Teradata data types

Návod

Vyhodnoťte dopad nepodporovaných datových typů v rámci přípravné fáze.

Most Teradata data types have a direct equivalent in Azure Synapse. The following table shows the Teradata data types that are unsupported in Azure Synapse together with the recommended mapping. In the table, Teradata column type is the type that's stored within the system catalog—for example, in DBC.ColumnsV.

Teradata column type Teradata data type Datový typ Azure Synapse
++ TD_ANYTYPE Not supported in Azure Synapse
A1 ARRAY Not supported in Azure Synapse
AN ARRAY Not supported in Azure Synapse
AT ČAS ČAS
BF BYTE BINARY
BO BLOB BLOB data type isn't directly supported but can be replaced with BINARY.
BV VARBYTE BINARY
CF VARCHAR CHAR
Oxid uhelnatý CLOB CLOB data type isn't directly supported but can be replaced with VARCHAR.
Životopis VARCHAR VARCHAR
D DECIMAL DECIMAL
DA Datum Datum
DH INTERVAL DAY TO HOUR INTERVAL data types aren't supported in Azure Synapse, but date calculations can be done with the date comparison functions (for example, DATEDIFF and DATEADD).
DM INTERVAL DAY TO MINUTE INTERVAL data types aren't supported in Azure Synapse, but date calculations can be done with the date comparison functions (for example, DATEDIFF and DATEADD).
DS INTERVAL OD DNE DO SEKUNDY INTERVAL data types aren't supported in Azure Synapse, but date calculations can be done with the date comparison functions (for example, DATEDIFF and DATEADD).
DT DATASET DATASET data type is supported in Azure Synapse.
DY INTERVAL DAY INTERVAL data types aren't supported in Azure Synapse, but date calculations can be done with the date comparison functions (for example, DATEDIFF and DATEADD).
F FLOAT FLOAT
Hm INTERVAL HOUR TO MINUTE INTERVAL data types aren't supported in Azure Synapse, but date calculations can be done with the date comparison functions (for example, DATEDIFF and DATEADD).
HR INTERVAL HOUR INTERVAL data types aren't supported in Azure Synapse, but date calculations can be done with the date comparison functions (for example, DATEDIFF and DATEADD).
HS INTERVAL HOUR TO SECOND INTERVAL data types aren't supported in Azure Synapse, but date calculations can be done with the date comparison functions (for example, DATEDIFF and DATEADD).
I1 BYTEINT TINYINT
I2 SMALLINT SMALLINT
I8 BIGINT BIGINT
I INTEGER INT
JN JSON JSON data type isn't currently directly supported within Azure Synapse, but JSON data can be stored in a VARCHAR field.
MI INTERVAL MINUTE INTERVAL data types aren't supported in Azure Synapse, but date calculations can be done with the date comparison functions (for example, DATEDIFF and DATEADD).
MO INTERVAL MONTH INTERVAL data types aren't supported in Azure Synapse, but date calculations can be done with the date comparison functions (for example, DATEDIFF and DATEADD).
MS INTERVAL MINUTE TO SECOND INTERVAL data types aren't supported in Azure Synapse, but date calculations can be done with the date comparison functions (for example, DATEDIFF and DATEADD).
N NUMBER NUMERIC
PD PERIOD(DATE) Can be converted to VARCHAR or split into two separate dates
PM PERIOD (TIMESTAMP WITH TIME ZONE) Can be converted to VARCHAR or split into two separate timestamps (DATETIMEOFFSET)
P.S. PERIOD(TIMESTAMP) Can be converted to VARCHAR or split into two separate timestamps (DATETIMEOFFSET)
PT PERIOD(TIME) Can be converted to VARCHAR or split into two separate times
PZ PERIOD (TIME WITH TIME ZONE) Can be converted to VARCHAR or split into two separate times but WITH TIME ZONE isn't supported for TIME
SC INTERVAL SECOND INTERVAL data types aren't supported in Azure Synapse, but date calculations can be done with the date comparison functions (for example, DATEDIFF and DATEADD).
SZ TIMESTAMP WITH TIME ZONE DATETIMEOFFSET
TS ČASOVÁ ZNAČKA DATETIME or DATETIME2
TZ TIME WITH TIME ZONE TIME WITH TIME ZONE isn't supported because TIME is stored using "wall clock" time only without a time zone offset.
XM XML XML data type isn't currently directly supported within Azure Synapse, but XML data can be stored in a VARCHAR field.
YM ČASOVÝ INTERVAL OD ROKU DO MĚSÍCE INTERVAL data types aren't supported in Azure Synapse, but date calculations can be done with the date comparison functions (for example, DATEDIFF and DATEADD).
YR INTERVAL YEAR INTERVAL data types aren't supported in Azure Synapse, but date calculations can be done with the date comparison functions (for example, DATEDIFF and DATEADD).

Use the metadata from the Teradata catalog tables to determine whether any of these data types are to be migrated and allow for this in the migration plan. For example, use a SQL query like this one to find any occurrences of unsupported data types that need attention.

SELECT
ColumnType, CASE
WHEN ColumnType = '++' THEN 'TD_ANYTYPE' 
WHEN ColumnType = 'A1' THEN 'ARRAY' WHEN 
ColumnType = 'AN' THEN 'ARRAY' WHEN 
ColumnType = 'BO' THEN 'BLOB'
WHEN ColumnType = 'CO' THEN 'CLOB'
WHEN ColumnType = 'DH' THEN 'INTERVAL DAY TO HOUR' WHEN 
ColumnType = 'DM' THEN 'INTERVAL DAY TO MINUTE' WHEN 
ColumnType = 'DS' THEN 'INTERVAL DAY TO SECOND' WHEN
ColumnType = 'DT' THEN 'DATASET'
WHEN ColumnType = 'DY' THEN 'INTERVAL DAY'
WHEN ColumnType = 'HM' THEN 'INTERVAL HOUR TO MINUTE' WHEN
ColumnType = 'HR' THEN 'INTERVAL HOUR'
WHEN ColumnType = 'HS' THEN 'INTERVAL HOUR TO SECOND' WHEN
ColumnType = 'JN' THEN 'JSON'
WHEN ColumnType = 'MI' THEN 'INTERVAL MINUTE' WHEN 
ColumnType = 'MO' THEN 'INTERVAL MONTH'
WHEN ColumnType = 'MS' THEN 'INTERVAL MINUTE TO SECOND' WHEN
ColumnType = 'PD' THEN 'PERIOD(DATE)'
WHEN ColumnType = 'PM' THEN 'PERIOD (TIMESTAMP WITH TIME ZONE)'
WHEN ColumnType = 'PS' THEN 'PERIOD(TIMESTAMP)' WHEN 
ColumnType = 'PT' THEN 'PERIOD(TIME)'
WHEN ColumnType = 'PZ' THEN 'PERIOD (TIME WITH TIME ZONE)' WHEN
ColumnType = 'SC' THEN 'INTERVAL SECOND'
WHEN ColumnType = 'SZ' THEN 'TIMESTAMP WITH TIME ZONE' WHEN
ColumnType = 'XM' THEN 'XML'
WHEN ColumnType = 'YM' THEN 'INTERVAL YEAR TO MONTH' WHEN
ColumnType = 'YR' THEN 'INTERVAL YEAR'
END AS Data_Type,
COUNT (*) AS Data_Type_Count FROM
DBC.ColumnsV
WHERE DatabaseName IN ('UserDB1', 'UserDB2', 'UserDB3') -- select databases to be migrated
GROUP BY 1,2
ORDER BY 1;

Návod

Nástroje a služby třetích stran můžou automatizovat úlohy mapování dat.

There are third-party vendors who offer tools and services to automate migration, including the mapping of data types. If a third-party ETL tool such as Informatica or Talend is already in use in the Teradata environment, those tools can implement any required data transformations.

Generování jazyka DDL (Data Definition Language)

Návod

Use existing Teradata metadata to automate the generation of CREATE TABLE and CREATE VIEW DDL for Azure Synapse.

Edit existing Teradata CREATE TABLE and CREATE VIEW scripts to create the equivalent definitions with modified data types as described previously if necessary. Typically, this involves removing extra Teradata-specific clauses such as FALLBACK or MULTISET.

Všechny informace, které určují aktuální definice tabulek a zobrazení v existujícím prostředí Teradata, se však udržují v tabulkách systémového katalogu. Toto je nejlepší zdroj těchto informací, protože je zaručeno, že je aktuální a kompletní. Mějte na paměti, že uživatelsky udržovaná dokumentace nemusí být synchronizovaná s aktuálními definicemi tabulek.

Access this information via views onto the catalog such as DBC.ColumnsV and generate the equivalent CREATE TABLE DDL statements for the equivalent tables in Azure Synapse.

Návod

Nástroje a služby třetích stran můžou automatizovat úlohy mapování dat.

Existují partneři Microsoftu , kteří nabízejí nástroje a služby pro automatizaci migrace, včetně mapování datových typů. Also, if a third-party ETL tool such as Informatica or Talend is already in use in the Teradata environment, that tool can implement any required data transformations.

SQL DML differences between Teradata and Azure Synapse

Jazyk SQL pro manipulaci s daty (DML)

Návod

Příkazy SQL DML SELECT, INSERT a UPDATE mají standardní základní prvky, ale mohou také implementovat různé možnosti syntaxe.

Standard ANSI SQL definuje základní syntaxi příkazů DML, jako jsou SELECT, INSERT, UPDATE a DELETE. Both Teradata and Azure Synapse use these commands, but in some cases there are implementation differences.

The following sections discuss the Teradata-specific DML commands that you should consider during a migration to Azure Synapse.

Rozdíly v syntaxi SQL DML

Be aware of these differences in SQL Data Manipulation Language (DML) syntax between Teradata SQL and Azure Synapse (T-SQL) when migrating:

  • QUALIFY: Teradata podporuje QUALIFY operátor. Například:

    SELECT col1
    FROM tab1
    WHERE col1='XYZ'
    QUALIFY ROW_NUMBER () OVER (PARTITION by
    col1 ORDER BY col1) = 1;
    

    Ekvivalentní syntaxe Azure Synapse je:

    SELECT * FROM (
    SELECT col1, ROW_NUMBER () OVER (PARTITION by col1 ORDER BY col1) rn
    FROM tab1 WHERE col1='XYZ'
    ) WHERE rn = 1;
    
  • Date arithmetic: Azure Synapse has operators such as DATEADD and DATEDIFF which can be used on DATE or DATETIME fields. Teradata podporuje přímé odčítání datumů, například SELECT DATE1 - DATE2 FROM...

  • In GROUP BY ordinal, explicitly provide the T-SQL column name.

  • LIKE ANY: Teradata podporuje LIKE ANY syntaxi, například:

    SELECT * FROM CUSTOMER
    WHERE POSTCODE LIKE ANY
    ('CV1%', 'CV2%', 'CV3%');
    

    The equivalent in Azure Synapse syntax is:

    SELECT * FROM CUSTOMER
    WHERE
    (POSTCODE LIKE 'CV1%') OR (POSTCODE LIKE 'CV2%') OR (POSTCODE LIKE 'CV3%');
    
  • V závislosti na nastavení systému může být porovnávání znaků v Teradatu ve výchozím nastavení bez rozlišování velkých a malých písmen. In Azure Synapse, character comparisons are always case sensitive.

Použití funkce EXPLAIN k ověření starší verze SQL

Návod

K vyhledání potenciálních problémů s migrací použijte skutečné dotazy ze stávajících systémových protokolů dotazů.

One way of testing legacy Teradata SQL for compatibility with Azure Synapse is to capture some representative SQL statements from the legacy system query logs, prefix those queries with EXPLAIN, and (assuming a "like-for-like" migrated data model in Azure Synapse with the same table and column names) run those EXPLAIN statements in Azure Synapse. Any incompatible SQL will throw an error—use this information to determine the scale of the recoding task. This approach doesn't require that data is loaded into the Azure environment, only that the relevant tables and views have been created.

Funkce, uložené procedury, triggery a sekvence

Návod

V rámci přípravné fáze vyhodnoťte počet a typ nemigrovaných objektů.

When migrating from a mature legacy data warehouse environment such as Teradata, there are often elements other than simple tables and views that need to be migrated to the new target environment. Examples of this include functions, stored procedures, triggers, and sequences.

V rámci přípravné fáze vytvořte inventář objektů, které je potřeba migrovat, a definujte metody pro jejich zpracování. Pak v plánu projektu přiřaďte odpovídající přidělení zdrojů.

There may be facilities in the Azure environment that replace the functionality implemented as either functions or stored procedures in the Teradata environment. In this case, it's often more efficient to use the built-in Azure facilities rather than recoding the Teradata functions.

Návod

Produkty a služby třetích stran můžou automatizovat migraci jiných než datových prvků.

Microsoft partners offer tools and services that can automate the migration.

Další informace o každém z těchto prvků najdete v následujících částech.

Funkce

As with most database products, Teradata supports system functions and user-defined functions within the SQL implementation. Při migraci na jinou databázovou platformu, jako je Azure Synapse, jsou k dispozici běžné systémové funkce a dají se migrovat beze změny. Některé systémové funkce můžou mít trochu odlišnou syntaxi, ale požadované změny je možné automatizovat. Systémové funkce, u kterých neexistuje žádný ekvivalent, například libovolné uživatelem definované funkce, může být potřeba překódovat pomocí jazyků dostupných v cílovém prostředí. Azure Synapse používá k implementaci uživatelem definovaných funkcí oblíbený jazyk Transact-SQL.

Uložené procedury

Většina moderních databázových produktů umožňuje ukládání procedur v databázi. Teradata poskytuje pro tento účel jazyk SPL. Uložená procedura obvykle obsahuje příkazy SQL a určitou procedurální logiku a může vracet data nebo stav.

The dedicated SQL pools of Azure Synapse Analytics also support stored procedures using T-SQL, so if you must migrate stored procedures, recode them accordingly.

Spouštěče

Azure Synapse doesn't support the creation of triggers, but you can implement them within Azure Data Factory.

Sequences

Azure Synapse sequences are handled in a similar way to Teradata, using IDENTITY to create surrogate keys or managed identity.

Teradata to T-SQL mapping

This table shows the Teradata to T-SQL compliant with Azure Synapse SQL data type mapping:

Teradata Data Type Datový typ Azure Synapse SQL
 bigint  bigint
 bool  bit
 boolean  bit
 byteint  tinyint
 char [(p)]  char [(p)]
 char varying [(p)]  varchar [(p)]
 character [(p)]  char [(p)]
 character varying [(p)]  varchar [(p)]
 date  date
 datetime  Datum a čas
 dec [(p[,s])]  decimal [(p[,s])]
 decimal [(p[,s])]  decimal [(p[,s])]
 double  float(53)
 dvojitá přesnost  float(53)
 float [(p)]  float [(p)]
 float4  float(53)
 float8  float(53)
 int  int
 int1 tinyint
 int2 smallint
 int4 int
 int8 bigint
 integer integer
 časový úsek Nepodporováno
 national char varying [(p)] nvarchar [(p)]
 national character [(p)] nchar [(p)]
 national character varying [(p)]  nvarchar [(p)]
 nchar [(p)]  nchar [(p)]
 numeric [(p[,s])]  numeric [(p[,s])
 nvarchar [(p)]  nvarchar [(p)]
 reálný  opravdový
 smallint  smallint
 Čas  Čas
 time with time zone  datetimeoffset
 time without time zone  Čas
 timespan   Nepodporováno
 časová značka  datetime2
 timetz  datetimeoffset
 varchar [(p)]  varchar [(p)]

Shrnutí

Typical existing legacy Teradata installations are implemented in a way that makes migration to Azure Synapse easy. Sql používají k analytickým dotazům na velké objemy dat a jsou v nějaké podobě dimenzionálního datového modelu. Díky těmto faktorům jsou vhodnými kandidáty pro migraci do Azure Synapse.

Pokud chcete minimalizovat úlohu migrace skutečného kódu SQL, postupujte podle těchto doporučení:

  • Počáteční migrace datového skladu by měla být as-is, aby se minimalizovalo riziko a doba trvání, a to i v případě, že konečné prostředí bude zahrnovat jiný datový model, jako je například trezor dat.

  • Consider using a Teradata instance in an Azure VM as a stepping stone as part of the migration process.

  • Understand the differences between Teradata SQL implementation and Azure Synapse.

  • Use metadata and query logs from the existing Teradata implementation to assess the impact of the differences and plan an approach to mitigate.

  • Automatizujte proces všude, kde je to možné, abyste minimalizovali chyby, rizika a čas migrace.

  • Zvažte použití specializovaných partnerů a služeb Microsoftu ke zjednodušení migrace.

Další kroky

To learn more about Microsoft and third-party tools, see the next article in this series: Tools for Teradata data warehouse migration to Azure Synapse Analytics.