DatasetTestUtils.equals not working as expected

Using Ignition 7.9.9. I would expect the following to print True, however it prints False.

from com.inductiveautomation.ignition.common.util import DatasetBuilder, DatasetTestUtils
from java.lang import String,Double
from java.util import Date
emptyDS1 = DatasetBuilder.newBuilder().colNames("col1", "col2", "col3").colTypes(Double, String, Date).build()
emptyDS2 = DatasetBuilder.newBuilder().colNames("col1", "col2", "col3").colTypes(Double, String, Date).build()
print(DatasetTestUtils.equals(emptyDS1, emptyDS2))

Only if I compare the same dataset (DatasetTestUtils.equals(emptyDS1, emptyDS1)) does it return True. Any ideas?

Huh, unfortunate. Looks like a problem stemming from the fact the method is called equals, and some kind of Jython interop problem.

1 Like

Thanks for checking it out. In the meantime, this works well enough for my purposes, hopefully it can help someone else too:

	def datasets_equals(newValue, oldValue):
		if (newValue.getRowCount() != oldValue.getRowCount()) or (newValue.getColumnCount() != oldValue.columnCount):
			return False
		else:
			for rowIndex in range(newValue.getRowCount()):
				for colIndex in range(newValue.getColumnCount()):
					if event.newValue.getValueAt(rowIndex, colIndex) != event.oldValue.getValueAt(rowIndex, colIndex):
						return False
		return True

(could check for column types and possibly other stuff too, but I know my particular data doesn’t require it)

You can use reflection to call the method:

from com.inductiveautomation.ignition.common import Dataset
method = DatasetTestUtils.getDeclaredMethod("equals", Dataset, Dataset)
method.invoke(DatasetTestUtils, emptyDS1, emptyDS2)

from org.apache.commons.lang3.reflect import MethodUtils
MethodUtils.invokeStaticMethod(DatasetTestUtils, "equals", emptyDS1, emptyDS2)
5 Likes