# Unable to delete data before inserting does not work while altering pipeline to earliest

**URL:** <https://www.singlestore.com/forum/t/unable-to-delete-data-before-inserting-does-not-work-while-altering-pipeline-to-earliest/8070>\
**Category:** Help\
**Tags:** pipelines\
**Created:** [January 7, 2025, 5:30am UTC](https://www.singlestore.com/forum/t/unable-to-delete-data-before-inserting-does-not-work-while-altering-pipeline-to-earliest/8070 "2025-01-07T05:30:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sowmya](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/s/a5b964/32.png) [@Sowmya](https://www.singlestore.com/forum/u/Sowmya)\
**Post date:** [January 7, 2025, 5:30am UTC](https://www.singlestore.com/forum/t/unable-to-delete-data-before-inserting-does-not-work-while-altering-pipeline-to-earliest/8070/1 "2025-01-07T05:30:48Z")

</div>

Dears,

We will be loading data to a Singlestore Columnstore table from Kafka through a procedure and pipeline. We have encountered an issue as below:

A customer uploads 3 attachments and the details of the attachment is stored in table and in the next case they upload 2 attachments .  
In the end table there should only be 2 attachments.  
For this case, we have written a syntax which deletes the 3 attachments and then inserts 2 attachments into the table.  
This works fine in normal scenarios but when our pipeline fails and pipeline is altered from the earliest, this logic behaves abnormally.  
Could you please help us a way out.

Here is the sample table, pipeline and procedure.

CREATE PIPELINE `delete_testing`  
AS LOAD DATA KAFKA ‘10.XX.XX.XX:XXXX/deals\_test’  
BATCH\_INTERVAL 2500  
INTO PROCEDURE `delete_test`  
FORMAT AVRO  
SCHEMA REGISTRY ‘[http://10.XX.XX.XX](http://10.XX.XX.XX):XXXX’  
(  
`deals_event` ← %  
);

CREATE OR REPLACE PROCEDURE `delete_test`(deals\_event\_batch query(`deals_event` JSON COLLATE utf8\_bin NULL)) RETURNS void AS

DECLARE p\_id\_batch query(`p_party_id` text,`p_data_content_type` text);

BEGIN

p\_id\_batch = select DISTINCT json\_extract\_string(deals\_event,“event”,“id”),  
json\_extract\_string(deals\_event,“datacontenttype”) from deals\_event\_batch as ppib;

delete from account\_manager as amg  
where amg.party\_id in(  
select DISTINCT ppie.p\_party\_id from p\_id\_batch as ppie);

INSERT INTO account\_manager(party\_id,id,name,email\_id,`role`)  
SELECT  
json\_extract\_string(json\_extract\_string(table\_col,“partyId”),“string”),  
json\_extract\_string(json\_extract\_string(table\_col,“id”),“string”),  
json\_extract\_string(json\_extract\_string(table\_col,“name”),“string”),  
json\_extract\_string(json\_extract\_string(table\_col,“email”),“string”),  
json\_extract\_string(json\_extract\_string(table\_col,“role”),“string”)  
from deals\_event  
left join table  
(json\_to\_array(json\_extract\_string(deals\_event,“event”,“organization”,“amanager”))) on true  
on duplicate key update  
name= values(name),  
email\_id= values(email\_id),  
role= values(role);  
END;

CREATE TABLE `account_manager` (  
`party_id` varchar(20) CHARACTER SET utf8 COLLATE utf8\_general\_ci NOT NULL,  
`id` varchar(20) CHARACTER SET utf8 COLLATE utf8\_general\_ci DEFAULT NULL,  
`name` varchar(50) CHARACTER SET utf8 COLLATE utf8\_general\_ci DEFAULT NULL,  
`email_id` varchar(60) CHARACTER SET utf8 COLLATE utf8\_general\_ci DEFAULT NULL,  
`role` varchar(50) CHARACTER SET utf8 COLLATE utf8\_general\_ci DEFAULT NULL,  
`operation_time` timestamp(6) NULL DEFAULT CURRENT\_TIMESTAMP(6),  
`operation_upd_time` timestamp(6) NULL DEFAULT CURRENT\_TIMESTAMP(6) ON UPDATE CURRENT\_TIMESTAMP(6),  
UNIQUE KEY `ids` (`party_id`) USING HASH,  
SHARD KEY `__SHARDKEY` (`party_id`),  
KEY `party_id` (`party_id`)  
) AUTOSTATS\_CARDINALITY\_MODE=PERIODIC AUTOSTATS\_HISTOGRAM\_MODE=CREATE SQL\_MODE=‘STRICT\_ALL\_TABLES’

---

<div class="post-metadata">

**Author:** ![srachamadugu](https://www.singlestore.com/forum/user_avatar/www.singlestore.com/srachamadugu/32/2173_2.png) [@srachamadugu](https://www.singlestore.com/forum/u/srachamadugu)\
**Post date:** [January 10, 2025, 12:13pm UTC](https://www.singlestore.com/forum/t/unable-to-delete-data-before-inserting-does-not-work-while-altering-pipeline-to-earliest/8070/2 "2025-01-10T12:13:23Z")

</div>

Hi Sowmya,

can you share in detail what you mean by alter pipeline from the earliest and what is meant by abnormal behavior

---

<div class="post-metadata">

**Author:** ![Sowmya](https://www.singlestore.com/forum/letter_avatar_proxy/v4/letter/s/a5b964/32.png) [@Sowmya](https://www.singlestore.com/forum/u/Sowmya)\
**Post date:** [January 14, 2025, 12:41pm UTC](https://www.singlestore.com/forum/t/unable-to-delete-data-before-inserting-does-not-work-while-altering-pipeline-to-earliest/8070/3 "2025-01-14T12:41:07Z")

</div>

Hi @srachamadugu,

PFB responses.

Kafka stores data in a sequential format(offsets), we load data into Single store table using a pipeline.  
The phrase earliest means loading the data from the start of the offsets.  
The query we use for this function - alter pipeline delete\_testing set offsets earliest.

Using the code mentioned, the data deletion is not happening as expected (explained in the problem statement) while altering from earliest which was meant as abnormal behavior.

---

<div class="post-metadata">

**Author:** ![srachamadugu](https://www.singlestore.com/forum/user_avatar/www.singlestore.com/srachamadugu/32/2173_2.png) [@srachamadugu](https://www.singlestore.com/forum/u/srachamadugu)\
**Post date:** [January 17, 2025, 10:38am UTC](https://www.singlestore.com/forum/t/unable-to-delete-data-before-inserting-does-not-work-while-altering-pipeline-to-earliest/8070/4 "2025-01-17T10:38:29Z")

</div>

Its quite difficult to comment what could go wrong, without knowing data shape and the order of events

in case of replays the kafka offsets are read from beginning and some offsets could be dropped by kafka in the beginning and because of that the items in a batch may differ from initial runs and this could be causing issues if the data of a customer is split across batches
