Multiple queryTagHistory result nulls at start and shift down data

Hello,
I try to return the history data of multiple tags together with either history binding or system.tag.queryTagHistory() in As Stored Mode(returnSize = -1). All of those tags are stored in the database with the same timestamp.
I even try to history data with system.tag.storeTagHistory() to force same t_stamp.

paths = ["[default]SIM/ramp 1", "[default]SIM/realistic", "[default]SIM/KV"]
dataset = system.tag.queryTagHistory(paths, startDate, endDate, aggregationMode = "LastValue", returnSize = -1)

The problem is the return dataset is started with nulls in the following order:
One-time Null for the second tag in the paths
Two times for the third tag in the paths
Three times for the fourth tag in the paths
And so on.. (n nulls for n+1 tags in the list)
As shown below image the time stamps are repeating for every 3 rows (which is equal to the number of tags)
Here I need to shift up the second tag one row and shift up the 3rd tag 2 times to make them sync together which extra load for every query.

So I wonder if is this a bug or if I did something wrong here to get this strange result.
What should I do to get rid of shifting down the data?

Display the t_stamp as milliseconds and you will see that they are recorded at different times. The repeated values are interpolated.

The Historian uses a narrow table and does not give a nice way to convert to wide. I gave up and created my own wide tables where needed and record each tag simultaneously.

The only other option is to loop through using a script and returning all the rows before a larger t_stamp change. Messy.

I put.SSS in a table to display mi-seconds and they are same, believe me.
Also, I store those in system.tag.storeTagHistory() in script with same t_stamp, so this is not the case.
Also why there are null values at the start? Don't you agree this is a bug?(for Wide format)
now I try to query them one by one (which is not efficient) and zip them together.

	paths = [tagPath + "/lng"]
	lngDataset = system.tag.queryTagHistory(paths, startDate, endDate, aggregationMode = "LastValue", returnSize = -1)
	lngDataset = system.dataset.toPyDataSet(lngDataset)

	paths = [tagPath + "/lat"]	
	latDataset = system.tag.queryTagHistory(paths, startDate, endDate, aggregationMode = "LastValue", returnSize = -1)
	latDataset = system.dataset.toPyDataSet(latDataset)


	for lng, lat in zip(lngDataset, latDataset):
		coordinates.append([lng[1], lat[1]])

I believe you!

I don't know, but the way it works is not obvious to the user and not well documented. I gave up on Historian except for long term data logging for diagnosis on Power Chart.

1 Like

Wide format is simply incompatible with "as stored". Use tall format and transform the result into separate lists (by grouping on tag path).

1 Like