cht42 commented on issue #7453:
URL: https://github.com/apache/arrow-rs/issues/7453#issuecomment-2839129097

   FYI, I'm using the following code to achieve this
   ```rust
   // Returns the raw string value of the JSON value. Used when incorrect types 
are
   // encountered in the JSON input. This is used to replicate Spark's behavior
   // when decoding JSON.
   fn decode_any(s: &mut String, tape: &Tape<'_>, pos: u32) -> Result<(), 
ArrowError> {
       match tape.get(pos) {
           TapeElement::StartObject(end) => {
               s.push('{');
               let mut cur_idx = pos + 1;
               let mut key = true;
               while cur_idx < end {
                   decode_any(s, tape, cur_idx)?;
                   cur_idx = tape.next(cur_idx, "json")?;
                   if cur_idx < end {
                       if key {
                           s.push(':');
                       } else {
                           s.push(',');
                       }
                       key = !key;
                   }
               }
   
               s.push('}');
           }
           TapeElement::StartList(end) => {
               s.push('[');
   
               let mut cur_idx = pos + 1;
               while cur_idx < end {
                   decode_any(s, tape, cur_idx)?;
                   cur_idx = tape.next(cur_idx, "json")?;
                   if cur_idx < end {
                       s.push(',');
                   }
               }
   
               s.push(']');
           }
           TapeElement::String(idx) => {
               s.push('"');
               s.push_str(tape.get_string(idx));
               s.push('"');
           }
           TapeElement::Number(idx) => s.push_str(tape.get_string(idx)),
           TapeElement::I64(high) => match tape.get(pos + 1) {
               TapeElement::I32(low) => {
                   let val = ((high as i64) << 32) | (low as u32) as i64;
                   s.push_str(&val.to_string());
               }
               _ => unreachable!(),
           },
           TapeElement::I32(n) => s.push_str(&n.to_string()),
           TapeElement::F32(n) => s.push_str(&n.to_string()),
           TapeElement::F64(high) => match tape.get(pos + 1) {
               TapeElement::F32(low) => {
                   let val = f64::from_bits(((high as u64) << 32) | low as u64);
                   s.push_str(&val.to_string());
               }
               _ => unreachable!(),
           },
           TapeElement::True => s.push_str("true"),
           TapeElement::False => s.push_str("false"),
           TapeElement::Null => s.push_str("null"),
           el => unreachable!("unexpected {:?}", el),
       }
   
       Ok(())
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to