I'm trying to import SSAS DMV metadata into SQL Server using a data flow in SSIS. In this example, I'm attempting to import data from the $SYSTEM.TMSCHEMA_PARTITIONS DMV. My select statement (which looks like SQL but is not SQL), is:
SELECT
[ID]
,[TableID]
,[Name]
,[Description]
,[DataSourceID]
,[QueryDefinition]
,[State]
,[Type]
,[PartitionStorageID]
,[Mode]
,[DataView]
,[ModifiedTime]
,[RefreshedTime]
,[SystemFlags]
,[ErrorMessage]
FROM $SYSTEM.TMSCHEMA_PARTITIONS
The QueryDefinition column contains records with several thousand characters. However the ExternalColumns section of the SSIS data source component is recognising the columns as DT_WSTR with 255 length. It's not possible to change the external column data type as it will keep reverting back. Nor is it possible to use CAST or CONVERT in the DMV select statement as per MS documentation:
The query engine for DMVs is the Data Mining parser. The DMV query syntax is based on the SELECT (DMX) statement. Although DMV query syntax is based on a SQL SELECT statement, it does not support the full syntax of a SELECT statement. Notably, JOIN, GROUP BY, LIKE, CAST, and CONVERT are not supported.
Naturally, I'm getting a truncation error. My question is, is there any way to change the way in which SSIS interprets the SSAS DMV metadata data types?
I've tried using order by (as a test) to return records with string length > 255 first, in order to force SSIS into thinking straight. It was to no avail.
Try adding the query with all the columns except the
QueryDefinitioncolumn, then define this column afterwards via the following steps. Going through this, I was able to set data type to DT_WSTR with a length of 4000 for both the External and Output Columns on the OLE DB Source component.QueryDefinitioncolumn and make sure the data types for the other columns are set appropriately.ValidateExternalMetadatato False on the OLE DB Source.QueryDefinitioncolumn in theSqlCommandfield on the Component Properties page.QueryDefinitioncolumn with the proper data type and longer length. Make a note of the value in theIDfield for this column.QueryDefinitioncolumn again with the same data type and length. In theExternalMetadataColumnIDfield, enter the same value that this column has in theIDfield in the External Columns folder to map these together.