Doris streamload 删除问题

Viewed 67

Doris版本 2.1.5

有一个表,表里的字段有这么些
id 主键
test_id not null 普通列
xxxxx 其他列

现在使用 streamload 进行删除数据。streamload 的代码大概如下:

  String loadUrl = String.format("http://%s:%s/api/%s/%s/_stream_load",
                host, port, database, table);
        Map<String, String> headerMap = new HashMap<>(32);
        headerMap.put(HttpHeaders.EXPECT, "100-continue");
        // 部分更新
        headerMap.put("partial_columns", "true");
        JsonNode jsonNode = DPUtil.parseJSON(jsonData);
        Set<String> strings = DPUtil.fieldsSet(jsonNode);
        // 列字段
        String columns = CollectionUtil.join(strings, ",", "`","`");
        headerMap.put("columns", columns);
        headerMap.put(HttpHeaders.AUTHORIZATION, basicAuthHeader(username, password));
        headerMap.put("merge_type", "DELETE");
        headerMap.put("label", UUID.randomUUID().toString());
        headerMap.put("column_separator", ",");
        headerMap.put("format", "json");
        HttpRequest httpRequest = HttpRequest.put(loadUrl)
                .body(jsonData)
                .charset(StandardCharsets.UTF_8)
                .setFollowRedirects(true)
                .removeHeader(HttpHeaders.CONTENT_LENGTH)
                .removeHeader(HttpHeaders.TRANSFER_ENCODING)
                .headerMap(headerMap, true);
        try(HttpResponse execute = httpRequest.execute();){
xxxx
}

删除数据时,使用的数据的主键删除,即:请求的参数仅有主键id : { "id":"1" }
但是有时会出现如下的报错, 提示 test_id 不可为空,并且这个异常,也不是可以稳定复现的:
[CANCELLED][INTERNAL_ERROR]tablet error: [E-207]the unmentioned column test_id should have default value or be nullable for newly inserted rows in non-strict mode partial update

1 Answers

由于Doris是整行存储的,对于用户没有提供的字段,也需要填充null值或者默认值。当用户的table schema定义中存在某些字段为not null,且没有提供默认值的时候,如果用户在部分列更新的导入中没有提供这些字段的值,Doris将无法这些缺失的字段填充值(无法填充nul,因为字段声明了not null;无法填充默认值,因为字段无默认值),所以这种情况Doris只能报错
解决方案:
1.修改table schema,将对应字段改成nullable或者设置一个默认值
2.在导入中始终为对应字段提供值