HSQLDB:奇怪的“唯一约束或索引违规”从 CSV 读取数据

发布于 2024-09-16 01:08:13 字数 2864 浏览 6 评论 0原文

我有一个工具可以读取 CSV 文件,使用 HSQLDB 从中进行选择,然后将结果保存为另一个 CSV 文件。更多信息:http://ondra.zizka .cz/stranky/programovani/java/apps/CsvCruncher-csv-manipulation-sql.texy

现在,当我将它用于某些任务时,我得到:

java -jar CsvCruncher-1.0.jar 结果。 csv foo.csv 'SELECT * FROM indata'

INFO:   SQL: CREATE TEXT TABLE indata ( xrelease VARCHAR(255), xtype VARCHAR(255), xartifact VARCHAR(255), xversion VARCHAR(255) )
INFO:   SQL: CREATE TEXT TABLE output ( XRELEASE VARCHAR(255), XTYPE VARCHAR(255), XARTIFACT VARCHAR(255), XVERSION VARCHAR(255) )
INFO:   User's SQL: INSERT INTO output (SELECT * FROM indata)
INFO: Database closed
Exception in thread "main" java.sql.SQLException: integrity constraint violation: unique constraint or index violation: SYS_IDX_10027
    at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCPreparedStatement.fetchResult(Unknown Source)
    at org.hsqldb.jdbc.JDBCPreparedStatement.executeUpdate(Unknown Source)
    at org.jboss.qa.cvscruncher.Cruncher.crunch(Cruncher.java:187)
    at org.jboss.qa.cvscruncher.App.main(App.java:26)
    at Crunch.main(Crunch.java:9)
Caused by: org.hsqldb.HsqlException: integrity constraint violation: unique constraint or index violation: SYS_IDX_10027
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.index.IndexAVL.insert(Unknown Source)
    at org.hsqldb.persist.RowStoreAVLDiskData.indexRow(Unknown Source)
    at org.hsqldb.Table.insertSingleRow(Unknown Source)
    at org.hsqldb.StatementDML.insertRowSet(Unknown Source)
    at org.hsqldb.StatementInsert.getResult(Unknown Source)
    at org.hsqldb.StatementDMQL.execute(Unknown Source)
    at org.hsqldb.Session.executeCompiledStatement(Unknown Source)
    at org.hsqldb.Session.execute(Unknown Source)
    ... 5 more

从日志中可以看出,没有创建索引,至少没有明确创建索引。我试图在HSQLDB的手册中找到一些自动创建的约束,但没有找到。

当我只执行 SELECT 1 FROM indata 时,就可以了。所以我想这与数据本身有关。对于这种情况,它们是: http://pastebin.com/8QiY2HXx (x 以防止关键字冲突)。

更新:

当我转储从 CSV 读取的数据时,有点奇怪:

 -------
 XRELEASE: 5.1.0-SNAPSHOT
 XTYPE: DEP
 XARTIFACT: org.apache.maven:maven-ant-tasks
5XVERSION: 2.0.9
 -------
 XRELEASE: 5.1.0-SNAPSHOT
 XTYPE: DEP
 XARTIFACT: org.jboss.seam.integration:jboss-seam-int-microcontainer
5XVERSION: 5.1.0.CR1
 -------
 XRELEASE: 5.1.0-SNAPSHOT
 XTYPE: DEP
 XARTIFACT: org.jboss.seam.integration:jboss-seam-int-jbossas
5XVERSION: 5.1.0.CR1
 -------
...

似乎 xversion 列被以某种方式修改了。 代码很简单 System.out.println(" "+ metaData.getColumnLabel(i) + ": "+ rs.getObject(i) );

知道什么会导致这种情况吗?

谢谢,昂德拉

I have a tool which reads a CSV file, selects from it using HSQLDB, and saves the result as another CSV file. More here: http://ondra.zizka.cz/stranky/programovani/java/apps/CsvCruncher-csv-manipulation-sql.texy

Now when I used it for some task, I have got:

java -jar CsvCruncher-1.0.jar result.csv foo.csv 'SELECT * FROM indata'

INFO:   SQL: CREATE TEXT TABLE indata ( xrelease VARCHAR(255), xtype VARCHAR(255), xartifact VARCHAR(255), xversion VARCHAR(255) )
INFO:   SQL: CREATE TEXT TABLE output ( XRELEASE VARCHAR(255), XTYPE VARCHAR(255), XARTIFACT VARCHAR(255), XVERSION VARCHAR(255) )
INFO:   User's SQL: INSERT INTO output (SELECT * FROM indata)
INFO: Database closed
Exception in thread "main" java.sql.SQLException: integrity constraint violation: unique constraint or index violation: SYS_IDX_10027
    at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCPreparedStatement.fetchResult(Unknown Source)
    at org.hsqldb.jdbc.JDBCPreparedStatement.executeUpdate(Unknown Source)
    at org.jboss.qa.cvscruncher.Cruncher.crunch(Cruncher.java:187)
    at org.jboss.qa.cvscruncher.App.main(App.java:26)
    at Crunch.main(Crunch.java:9)
Caused by: org.hsqldb.HsqlException: integrity constraint violation: unique constraint or index violation: SYS_IDX_10027
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.index.IndexAVL.insert(Unknown Source)
    at org.hsqldb.persist.RowStoreAVLDiskData.indexRow(Unknown Source)
    at org.hsqldb.Table.insertSingleRow(Unknown Source)
    at org.hsqldb.StatementDML.insertRowSet(Unknown Source)
    at org.hsqldb.StatementInsert.getResult(Unknown Source)
    at org.hsqldb.StatementDMQL.execute(Unknown Source)
    at org.hsqldb.Session.executeCompiledStatement(Unknown Source)
    at org.hsqldb.Session.execute(Unknown Source)
    ... 5 more

As can be seen from the log, there are no indexes created, at least not explicitely. I have tried to find some auto-created constraint in HSQLDB's manual, didn't find.

When I do only SELECT 1 FROM indata, it's fine. So I guess it's something with the data itself. For that case, here they are: http://pastebin.com/8QiY2HXx (x to prevent keyword clash).

Update:

When I dump the data read from the CSV, it's a bit weird:

 -------
 XRELEASE: 5.1.0-SNAPSHOT
 XTYPE: DEP
 XARTIFACT: org.apache.maven:maven-ant-tasks
5XVERSION: 2.0.9
 -------
 XRELEASE: 5.1.0-SNAPSHOT
 XTYPE: DEP
 XARTIFACT: org.jboss.seam.integration:jboss-seam-int-microcontainer
5XVERSION: 5.1.0.CR1
 -------
 XRELEASE: 5.1.0-SNAPSHOT
 XTYPE: DEP
 XARTIFACT: org.jboss.seam.integration:jboss-seam-int-jbossas
5XVERSION: 5.1.0.CR1
 -------
...

Which seems like the xversion column is modified somehow.
The code is simply System.out.println(" "+ metaData.getColumnLabel(i) + ": "+ rs.getObject(i) );

Any idea what can cause this?

Thanks, Ondra

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

咽泪装欢 2024-09-23 01:08:13

问题出在输入文件中 - 它包含 0x0D 作为换行符,并且不知何故它破坏了 HSQLDB。我会报告这一点,以便他们检查。至少它应该拒绝无效输入或更好地转换换行符。

The problem was in the input file - it contained 0x0D as newlines, and somehow it broke HSQLDB. I'll report that so they can check. At least it should refuse invalid input or better transform the newlines.

与君绝 2024-09-23 01:08:13

请检查数据库的 .script 和 .log 文件。这将显示数据库中实际的表定义。如果找不到原因,请通过错误跟踪器(请参阅“支持”页面)和示例数据文件向 HSQLDB 报告错误。错误很快得到修复。

Please check the .script and .log files for the database. This will show what the actual table definitions are in the database. If you cannot find the cause, then report a bug to HSQLDB via the Bug Tracker (see the "support" page) with sample data files. Bugs are fixed quickly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文