Giter Site home page Giter Site logo

Cannot bulk load. The bulk data stream was incorrectly specified as sorted or the data violates a uniqueness constraint imposed by the target table. about smartbulkcopy HOT 5 CLOSED

azure-samples avatar azure-samples commented on August 16, 2024
Cannot bulk load. The bulk data stream was incorrectly specified as sorted or the data violates a uniqueness constraint imposed by the target table.

from smartbulkcopy.

Comments (5)

gavindew avatar gavindew commented on August 16, 2024

Ok, so the issue seems to be caused by this:
public string GetOrderBy()
{
return SourceTableInfo.PrimaryIndex.GetOrderBy(excludePartitionColumn:true);
}

This means the ORDER BY generated in the SELECT statement excludes the partitioning key, but the ORDER BY added to the BulkCopy itself includes the partitioning key. When I change excludePartitionColumn to false, it works fine.

from smartbulkcopy.

yorek avatar yorek commented on August 16, 2024

Good catch, thanks! Not sure I understand what are the conditions that make this issue happen. You have the table on source and the destination created with the same partitioning function and scheme. Both have an Clustered Index.
Adding the Partition column to the order by is needed to make sure sorting does not happen on the destination.
Are you able to create a repro so that I can take a look at it?
Thanks!

from smartbulkcopy.

gavin-eq avatar gavin-eq commented on August 16, 2024

This script should highlight the issue: By excluding the partition column, the sort order of the data will be different on select and in bulk copy object.

CREATE PARTITION FUNCTION pfTest AS RANGE LEFT FOR VALUES (N'2018-12-31T00:00:00.000', N'2019-12-31T00:00:00.000')
GO
CREATE PARTITION SCHEME [psTest] AS PARTITION [pfTest] TO ([PRIMARY], [PRIMARY], [PRIMARY])
GO
CREATE TABLE PartitionTest (
PartitionDate date not null,
TransactionId int not null,
CategoryId int not null
CONSTRAINT [PK_PartitionTest] PRIMARY KEY CLUSTERED
(
PartitionDate ASC,
TransactionId ASC,
CategoryId ASC
) ON psTest
)
GO
INSERT INTO PartitionTest (PartitionDate, TransactionId, CategoryId)
VALUES
('2018-01-01', 2, 1),
('2018-01-02', 1, 1)

from smartbulkcopy.

yorek avatar yorek commented on August 16, 2024

Thanks, will take a look ASAP

from smartbulkcopy.

yorek avatar yorek commented on August 16, 2024

Thanks, I was able to repro the problem and fixed it. Added also unit tests and CI/CD pipeline to make sure not to introduce regression bugs.
Fixed here: b85f6b8

from smartbulkcopy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.