Skip to content

Commit

Permalink
fix(sink): handle visibility in remote sink (#12463)
Browse files Browse the repository at this point in the history
  • Loading branch information
st1page authored Sep 20, 2023
1 parent 0515f01 commit 6500c1e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/common/src/array/arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ use crate::types::{Int256, StructType};
use crate::util::iter_util::ZipEqDebug;

// Implement bi-directional `From` between `DataChunk` and `arrow_array::RecordBatch`.

// note: DataChunk -> arrow RecordBatch will IGNORE the visibilities.
impl TryFrom<&DataChunk> for arrow_array::RecordBatch {
type Error = ArrayError;

fn try_from(chunk: &DataChunk) -> Result<Self, Self::Error> {
if !chunk.is_compacted() {
let c = chunk.clone();
return Self::try_from(&c.compact());
}
let columns: Vec<_> = chunk
.columns()
.iter()
Expand Down
3 changes: 3 additions & 0 deletions src/common/src/array/stream_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ impl StreamChunk {
}

pub fn to_protobuf(&self) -> PbStreamChunk {
if !self.is_compacted() {
return self.clone().compact().to_protobuf();
}
PbStreamChunk {
cardinality: self.cardinality() as u32,
ops: self.ops.iter().map(|op| op.to_protobuf() as i32).collect(),
Expand Down
4 changes: 4 additions & 0 deletions src/connector/src/sink/clickhouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ impl ClickHouseSinkWriter {
)?;
for (op, row) in chunk.rows() {
if op != Op::Insert {
tracing::warn!(
"append only click house sink receive an {:?} which will be ignored.",
op
);
continue;
}
let mut clickhouse_filed_vec = vec![];
Expand Down
2 changes: 1 addition & 1 deletion src/connector/src/sink/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ where
async fn write_batch(&mut self, chunk: StreamChunk) -> Result<()> {
let payload = match self.payload_format {
SinkPayloadFormat::Json => {
let mut row_ops = vec![];
let mut row_ops = Vec::with_capacity(chunk.cardinality());
let enc = JsonEncoder::new(&self.schema, None, TimestampHandlingMode::String);
for (op, row_ref) in chunk.rows() {
let map = enc.encode(row_ref)?;
Expand Down
2 changes: 1 addition & 1 deletion src/connector/src/sink/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::sink::Result;

pub fn chunk_to_json(chunk: StreamChunk, schema: &Schema) -> Result<Vec<String>> {
let encoder = JsonEncoder::new(schema, None, TimestampHandlingMode::Milli);
let mut records: Vec<String> = Vec::with_capacity(chunk.capacity());
let mut records: Vec<String> = Vec::with_capacity(chunk.cardinality());
for (_, row) in chunk.rows() {
let record = Value::Object(encoder.encode(row)?);
records.push(record.to_string());
Expand Down

0 comments on commit 6500c1e

Please sign in to comment.