%3CLINGO-SUB%20id%3D%22lingo-sub-1257397%22%20slang%3D%22en-US%22%3ESQL%202019%20PolyBase%3A%20Fractional%20Truncation%20Issue%20When%20Using%20Data%20Virtualization%20in%20Azure%20Data%20Studio%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1257397%22%20slang%3D%22en-US%22%3E%3CP%3E%3CFONT%20size%3D%226%22%3EProblem%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3EConsider%20the%20following%20scenario.%20You%20have%20a%20table%20in%20an%20Oracle%20which%20uses%20the%20Oracle%20date%20datatype%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3Ecreate%20table%20OracleUser.table1%20(c1%20date)%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20insert%20a%20row%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3Einsert%20into%20OracleUser.table1%20values(to_date('2019%2F12%2F23%2018%3A59%3A59'%2C'yyyy%2Fmm%2Fdd%20hh24%3Ami%3Ass'))%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20use%20the%20Azure%20Data%20Studio%20Data%20Virtualization%20extension%20to%20create%20a%20PolyBase%20external%20table%20in%20SQL%20Server%202019%20database%20'PB19Oracle19'%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Image1.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F179875iE573140FE9961281%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22Image1.png%22%20alt%3D%22Image1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EChoose%20Oracle%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Image2.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F179878i6DECE0B19237C86D%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22Image2.png%22%20alt%3D%22Image2.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%E2%80%83%3C%2FP%3E%0A%3CP%3EYou%20will%20need%20to%20have%20already%20created%20the%20External%20Data%20Source%20in%20the%20EDS_PB19Oracle19%20database.%20After%20that%20was%20created%20you%20will%20see%20it%20in%20the%20External%20Data%20Source%20drop%20down.%20Enter%20the%20Service%20name%20%2F%20SID%20(which%20is%20the%20SERVICE_NAME%20in%20tnsnames.ora%20on%20the%20server%20where%20Oracle%20is%20installed)%20and%20click%20Next.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CDIV%20id%3D%22tinyMceEditorNathanMSFT_2%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Image2.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F179880iE684EEF7E9CF4D04%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22Image2.png%22%20alt%3D%22Image2.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EExpand%20the%20external%20data%20source%20%26gt%3B%20tables%20and%20select%20the%20table%20(TABLE1)%20you%20are%20using%20as%20the%20Oracle%20source%20table%20and%20click%20Next.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Image2.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F179881i16A4B9C52A3185C7%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22Image2.png%22%20alt%3D%22Image2.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%E2%80%83%3C%2FP%3E%0A%3CP%3EClick%20Create.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAfter%20this%2C%20when%20you%20try%20to%20query%20the%20table%2C%20you%20get%20the%20following%20error%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CFONT%20color%3D%22%23FF0000%22%3EMsg%207320%2C%20Level%2016%2C%20State%20110%2C%20Line%209%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CFONT%20color%3D%22%23FF0000%22%3ECannot%20execute%20the%20query%20%22Remote%20Query%22%20against%20OLE%20DB%20provider%20%22MSOLEDBSQL%22%20for%20linked%20server%20%22(null)%22.%20105082%3BGeneric%20ODBC%20error%3A%20%5BMicrosoft%5D%5BODBC%20Oracle%20Wire%20Protocol%20driver%5DFractional%20truncation.%20Error%20in%20column%201.%20.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20check%20the%20table%20definition%2C%20you'll%20see%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECREATE%20EXTERNAL%20TABLE%20%5Bdbo%5D.%5BTABLE1%5D%3C%2FP%3E%0A%3CP%3E(%3C%2FP%3E%0A%3CP%3E%5BC1%5D%20%5BDATE%5D%20NULL%3C%2FP%3E%0A%3CP%3E)%3C%2FP%3E%0A%3CP%3EWITH%20(DATA_SOURCE%20%3D%20%5BEDS_PB19Oracle19%5D%2CLOCATION%20%3D%20N'%5Borcl.SQLPB.LOCAL%5D.%5BORACLEUSER%5D.%5BTABLE1%5D')%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%226%22%3ECause%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3ESQL%20Server%20%22DATE%22%20datatype%20is%20incompatible%20with%20Oracle%20datatype%20%22date%22.%20This%20is%20a%20bug%20in%20Azure%20Data%20Studio%20where%20incompatible%20datatype%20DATE%20is%20used%20in%20scripting%20the%20table%20definition.%20The%20compatible%20datatype%20in%20SQL%20Server%20is%20actually%20DATETIME2.%20Click%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fpolybase%2Fpolybase-type-mapping%3Fview%3Dsql-server-ver15%23oracle-type-mapping-reference%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E%20to%20see%20a%20list%20of%20data%20type%20mapping%20for%20SQL%20Server%20PolyBase%20feature%20(includes%20Oracle%20and%20other%20supported%20external%20data%20sources).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%226%22%3EResolution%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3ETo%20work%20around%20the%20issue%2C%20you%20can%20drop%20the%20table%20and%20recreate%20it%20with%20the%20correct%20datatype%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECREATE%20EXTERNAL%20TABLE%20%5Bdbo%5D.%5BTABLE1%5D%3C%2FP%3E%0A%3CP%3E(%3C%2FP%3E%0A%3CP%3E%5BC1%5D%20%5BDATETIME2%5D%20NULL%3C%2FP%3E%0A%3CP%3E)%3C%2FP%3E%0A%3CP%3EWITH%20(DATA_SOURCE%20%3D%20%5BEDS_PB19Oracle19%5D%2CLOCATION%20%3D%20N'%5Borcl.SQLPB.LOCAL%5D.%5BORACLEUSER%5D.%5BTABLE1%5D')%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20bug%20has%20been%20fixed%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fazuredatastudio%2Fissues%3Fq%3Dis%253Aissue%2Bis%253Aclosed%2Bmilestone%253A%2522February%2B2020%2522%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EFebruary%202020%20release%3C%2FA%3E%20of%20Azure%20Data%20Studio.%20You%20can%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Fazure-data-studio%2Fdownload-azure-data-studio%3Fview%3Dsql-server-ver15%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Edownload%20and%20install%20Azure%20Data%20Studio%3C%2FA%3E%20and%20have%20the%20most%20recent%20release%2C%20or%20just%20start%20Azure%20Data%20Studio%20and%20you%20will%20be%20prompted%20to%20update.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%226%22%3EMore%20about%20this%20behavior%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3EThe%20bug%20is%20something%20that%20is%20fixed%20in%20Azure%20Data%20Studio%20to%20better%20align%20the%20data%20type%20mapping%20between%20SQL%20Server%20and%20Oracle.%20However%2C%20the%20fact%20that%20the%20table%20create%20was%20allowed%20by%20PolyBase%20is%20NOT%20a%20bug.%20Data%20types%20DATE%2C%20DATETIME%2C%20and%20DATETIME2%20are%20all%20in%20the%20same%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Ft-sql%2Ffunctions%2Fdate-and-time-data-types-and-functions-transact-sql%3Fview%3Dsql-server-ver15%23DateandTimeDataTypes%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Efamily%20of%20data%20types%3C%2FA%3E.%20If%20the%20data%20from%20Oracle%20is%20being%20processed%20in%20the%20context%20of%20a%20data%20type%20in%20SQL%20Server%20and%20there%20is%20a%20loss%20of%20precision%20or%20truncation%20of%20the%20data%2C%20we%20will%20raise%20the%20%22Fractional%20truncation%22%20error%2C%20which%20is%20essentially%20a%20runtime%20error.%20PolyBase%20allows%20this%20behavior%20as%20it%20allows%20users%20to%20specify%20narrower%20types%20than%20the%20backend%20if%20they%20know%20the%20actual%20data%20isn't%20going%20to%20exceed%20the%20limitations%20of%20the%20type%20used%20in%20the%20external%20table%20definition.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1257397%22%20slang%3D%22en-US%22%3E%3CP%20style%3D%22margin%3A%200in%3B%20font-family%3A%20Calibri%3B%20font-size%3A%2011.0pt%3B%22%3EMy%20colleague%20Liwei%20Yin%20recently%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fsql-server-support%2Fuse-data-virtualization-extension-of-azure-data-studio-to-create%2Fba-p%2F1052186%22%20target%3D%22_blank%22%3Eblogged%20about%3C%2FA%3E%20how%20to%20use%20the%20Data%20Virtualization%20extension%20in%20Azure%20Data%20Studio%20for%20creating%20PolyBase%20external%20tables%20for%20Oracle%20data%20sources.%20If%20you've%20done%20any%20work%20in%20this%20area%20and%20have%20Oracle%20tables%20that%20utilize%20columns%20with%20%3CSPAN%20style%3D%22font-weight%3A%20bold%3B%22%3Edate%3C%2FSPAN%3E%20datatype%2C%20you%20may%20have%20run%20into%20this%20issue.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1257397%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPolyBase%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESQL%202019%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

Problem

Consider the following scenario. You have a table in an Oracle which uses the Oracle date datatype:

 

create table OracleUser.table1 (c1 date);

 

You insert a row:

 

insert into OracleUser.table1 values(to_date('2019/12/23 18:59:59','yyyy/mm/dd hh24:mi:ss'));

 

You use the Azure Data Studio Data Virtualization extension to create a PolyBase external table in SQL Server 2019 database 'PB19Oracle19':

 

Image1.png

 

Choose Oracle

 

Image2.png

You will need to have already created the External Data Source in the EDS_PB19Oracle19 database. After that was created you will see it in the External Data Source drop down. Enter the Service name / SID (which is the SERVICE_NAME in tnsnames.ora on the server where Oracle is installed) and click Next.

 

 

Image2.png

 

Expand the external data source > tables and select the table (TABLE1) you are using as the Oracle source table and click Next.

 

Image2.png

Click Create.

 

After this, when you try to query the table, you get the following error:

 

Msg 7320, Level 16, State 110, Line 9

Cannot execute the query "Remote Query" against OLE DB provider "MSOLEDBSQL" for linked server "(null)". 105082;Generic ODBC error: [Microsoft][ODBC Oracle Wire Protocol driver]Fractional truncation. Error in column 1. .

 

If you check the table definition, you'll see:

 

CREATE EXTERNAL TABLE [dbo].[TABLE1]

(

[C1] [DATE] NULL

)

WITH (DATA_SOURCE = [EDS_PB19Oracle19],LOCATION = N'[orcl.SQLPB.LOCAL].[ORACLEUSER].[TABLE1]')

 

Cause

SQL Server "DATE" datatype is incompatible with Oracle datatype "date". This is a bug in Azure Data Studio where incompatible datatype DATE is used in scripting the table definition. The compatible datatype in SQL Server is actually DATETIME2. Click here to see a list of data type mapping for SQL Server PolyBase feature (includes Oracle and other supported external data sources).

 

Resolution

To work around the issue, you can drop the table and recreate it with the correct datatype:

 

CREATE EXTERNAL TABLE [dbo].[TABLE1]

(

[C1] [DATETIME2] NULL

)

WITH (DATA_SOURCE = [EDS_PB19Oracle19],LOCATION = N'[orcl.SQLPB.LOCAL].[ORACLEUSER].[TABLE1]')

 

This bug has been fixed in the February 2020 release of Azure Data Studio. You can download and install Azure Data Studio and have the most recent release, or just start Azure Data Studio and you will be prompted to update.

 

More about this behavior

The bug is something that is fixed in Azure Data Studio to better align the data type mapping between SQL Server and Oracle. However, the fact that the table create was allowed by PolyBase is NOT a bug. Data types DATE, DATETIME, and DATETIME2 are all in the same family of data types. If the data from Oracle is being processed in the context of a data type in SQL Server and there is a loss of precision or truncation of the data, we will raise the "Fractional truncation" error, which is essentially a runtime error. PolyBase allows this behavior as it allows users to specify narrower types than the backend if they know the actual data isn't going to exceed the limitations of the type used in the external table definition.