Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "fix: merge predicate for concurrent writes" #2322

Conversation

Blajda
Copy link
Collaborator

@Blajda Blajda commented Mar 23, 2024

reverts #2291

Introduces a regression to merge that occurred before #2158

Causes the following test to fail

async fn test_merge_pushdowns() {
    //See #2158
    let schema = vec![
        StructField::new(
            "id".to_string(),
            DataType::Primitive(PrimitiveType::String),
            true,
        ),
        StructField::new(
            "cost".to_string(),
            DataType::Primitive(PrimitiveType::Float),
            true,
        ),
        StructField::new(
            "month".to_string(),
            DataType::Primitive(PrimitiveType::String),
            true,
        ),
    ];

    let arrow_schema = Arc::new(ArrowSchema::new(vec![
        Field::new("id", ArrowDataType::Utf8, true),
        Field::new("cost", ArrowDataType::Float32, true),
        Field::new("month", ArrowDataType::Utf8, true),
    ]));

    let table = DeltaOps::new_in_memory()
        .create()
        .with_columns(schema)
        .await
        .unwrap();

    let ctx = SessionContext::new();
    let batch = RecordBatch::try_new(
        Arc::clone(&arrow_schema.clone()),
        vec![
            Arc::new(arrow::array::StringArray::from(vec!["A", "B"])),
            Arc::new(arrow::array::Float32Array::from(vec![Some(10.15), None])),
            Arc::new(arrow::array::StringArray::from(vec![
                "2023-07-04",
                "2023-07-04",
            ])),
        ],
    )
    .unwrap();

    let table = DeltaOps(table)
        .write(vec![batch.clone()])
        .with_save_mode(SaveMode::Append)
        .await
        .unwrap();
    assert_eq!(table.version(), 1);
    assert_eq!(table.get_files_count(), 1);

    let batch = RecordBatch::try_new(
        Arc::clone(&arrow_schema.clone()),
        vec![
            Arc::new(arrow::array::StringArray::from(vec!["A", "B"])),
            Arc::new(arrow::array::Float32Array::from(vec![Some(12.15), Some(11.15)])),
            Arc::new(arrow::array::StringArray::from(vec![
                "2023-07-04",
                "2023-07-04",
            ])),
        ],
    ).unwrap();
    let source = ctx.read_batch(batch).unwrap();

    let (table, _metrics) = DeltaOps(table)
        .merge(source, "target.id = source.id and target.cost is null")
        .with_source_alias("source")
        .with_target_alias("target")
        .when_matched_update(|insert| {
            insert
                .update("id", "target.id")
                .update("cost", "source.cost")
                .update("month", "target.month")
        })
        .unwrap()
        .await
        .unwrap();

    let expected = vec![
"+----+-------+------------+",
"| id | cost  | month      |",
"+----+-------+------------+",
"| A  | 10.15 | 2023-07-04 |",
"| B  | 11.15 | 2023-07-04 |",
"+----+-------+------------+",
    ];
    let actual = get_data(&table).await;
    assert_batches_sorted_eq!(&expected, &actual);
}

@github-actions github-actions bot added the binding/rust Issues for the Rust crate label Mar 23, 2024
Copy link

ACTION NEEDED

delta-rs follows the Conventional Commits specification for release automation.

The PR title and description are used as the merge commit message. Please update your PR title and description to match the specification.

@Blajda Blajda closed this Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
binding/rust Issues for the Rust crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant