opengeospatial / ets-gpkg12

GeoPackage 1.2 Executable Test Suite
Other
7 stars 10 forks source link

Feature Geometry Encoding Testing returns java.lang.NullPointerException #127

Closed phidrho closed 1 week ago

phidrho commented 6 months ago

Hi,

while trying to validate my GPKG file (attached) I get only one test passed (geopackage Version) and all other skipped. Only information that I got is for feature Geometry Encoding Testing where I got Reason of failure: java.lang.RuntimeException: java.lang.NullPointerException. Documentation says that this test should throw SQL Exception:

public void featureGeometryEncodingTesting(
    String thisTableName,
    String thisColumnName,
    String geomType,
    Integer srs_id,
    byte z_flag,
    byte m_flag)
  throws SQLException
phidrho commented 6 months ago

It seems that there is some bug related to tests when indexes are used in SQLite/GPKG file.

<test-method status="FAIL" signature="initCommonFixture(org.testng.ITestContext)[pri:0, instance:org.opengis.cite.gpkg12.core.DataContentsTests@20f50c7b]" name="initCommonFixture" is-config="true" duration-ms="0" started-at="2024-04-25T13:07:54Z" finished-at="2024-04-25T13:07:54Z">
          <params>
            <param index="0">
              <value>
                <![CDATA[org.testng.TestRunner@57c70b96]]>
              </value>
            </param>
          </params>
          <exception class="java.sql.SQLException">
            <message>
              <![CDATA[[SQLITE_CORRUPT]  The database disk image is malformed (malformed database schema (idx_un-adrese_cestice) - near "(": syntax error)]]>
            </message>
          </exception> <!-- java.sql.SQLException -->
          <reporter-output>
          </reporter-output>
        </test-method> <!-- initCommonFixture -->

Here is my DDL for this index, and as I've investigated it seems that It's not recommended to use "UNIQUE" keyword if expressions are used (ifnull() in my case).

CREATE UNIQUE INDEX "idx_un-adrese_cestice" ON ADRESE_CESTICE (
    CESTICA_ID COLLATE RTRIM,
    ifnull(ADRESA_OPISNA, '¤_¤_¤') COLLATE NOCASE,
    ifnull(NASELJE, '¤_¤_¤') COLLATE NOCASE,
    ifnull(NASELJE_MBR, '¤_¤_¤') COLLATE RTRIM,
    ifnull(ULICA, '¤_¤_¤') COLLATE NOCASE,
    ifnull(ULICA_RBR, '¤_¤_¤') COLLATE RTRIM
);

When I tried to remove UNIQUE keyword:

CREATE INDEX "idx_un-adrese_cestice" ON ADRESE_CESTICE (
    CESTICA_ID COLLATE RTRIM,
    ifnull(ADRESA_OPISNA, '¤_¤_¤') COLLATE NOCASE,
    ifnull(NASELJE, '¤_¤_¤') COLLATE NOCASE,
    ifnull(NASELJE_MBR, '¤_¤_¤') COLLATE RTRIM,
    ifnull(ULICA, '¤_¤_¤') COLLATE NOCASE,
    ifnull(ULICA_RBR, '¤_¤_¤') COLLATE RTRIM
);

then I got another error on "COLLATE" keyword. There should not be any problems with this syntax according to official graph: DDL for indexes

There is a note about SQLite version in official documentation that may be important (I don't know what version is used for tests):

Indexes on expression will not work with versions of SQLite prior to [version 3.9.0](https://sqlite.org/releaselog/3_9_0.html) (2015-10-14).
dstenger commented 6 months ago

Thanks for reporting. We will do further investigation.

phidrho commented 6 months ago

I have successfully narrowed down the issue. Problem with validation happens when expression is used inside index.

I am attaching zip file with 3 GPKG files:

1) OK_minimal_vector_gpkg.gpkg

GPKG VALIDATION BUG.zip