1

I've been trying to extract a table from a blob column in a database that was converted into a hex string in the process. I'm using R for all my job. A capture of the BLOB data column is highlighted below:

DATA column is a hex string coming from a BLOB column in a database

enter image description here

The problem is that the data when inspected in raw form is shifted one position ahead, completely modifying the conversion to my numeric arrays when I make the final conversion. A capture of the problem is highlighted below:

The first chunk is the right data, the second chunk is the data shifted one position ahead

enter image description here

My question is, how do I move the data one position behind?

Is there any package in R or Python capable of doing that shift?

I've been trying with hex2raw function from wkb package without success. Same with decode functions in Python.

Charles Han
  • 1,920
  • 2
  • 10
  • 19
  • 1
    Welcome! Can you please [read about why text is better than images of text](//meta.stackoverflow.com/a/285557/11107541) and then [edit] to convert your images of textual data into actual text? See [/editing-help#code](/editing-help#code) for how to format code blocks. – starball Jan 09 '23 at 23:15

1 Answers1

1

In R, You can "shift" you data numerically

data <- as.raw(sample(256,10) - 1)
data2 <- as.raw((as.integer(data) * 16L) %% 256L + ( c(data[-1], 0L) %/% 16L)  )


data
#>  [1] 89 af 4f 94 66 e8 84 c1 93 01
data2
#>  [1] 9a f4 f9 46 6e 88 4c 19 30 10

EDIT

Other way:

data3 <- as.raw(
  as.integer(rawShift(data, 4)) + 
  as.integer(rawShift(c(data[-1],as.raw(0)), -4)))


Ric
  • 5,362
  • 1
  • 10
  • 23
  • It helped Ric, thanks a lot...but as you can see in the second picture, the right data has 22912 entries against 15379 from the conversion of the hex string. Any reason behind the difference between these two objects? – Ricardo Soto Jan 10 '23 at 16:17
  • It depends on the DB, on whether the data is stored correctly, the extraction process, the data itself. Sadly, I don't known so far. – Ric Jan 10 '23 at 18:08