[
https://issues.apache.org/jira/browse/CALCITE-2748?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16724364#comment-16724364
]
Alexander Shilov commented on CALCITE-2748:
-------------------------------------------
This is the simplest example:
{code:java}
val table = object : AbstractTable(), ModifiableTable {
private val collection = ArrayList<Any?>()
override fun getRowType(typeFactory: RelDataTypeFactory): RelDataType {
return typeFactory.builder()
.add("foo", SqlTypeName.INTEGER)
.build()
}
override fun getModifiableCollection() = collection
override fun getElementType() = Array<Any?>::class.java
override fun toModificationRel(
cluster: RelOptCluster?, table: RelOptTable?, catalogReader:
Prepare.CatalogReader?,
child: RelNode?, operation: TableModify.Operation?, updateColumnList:
MutableList<String>?,
sourceExpressionList: MutableList<RexNode>?, flattened: Boolean
): TableModify {
return LogicalTableModify.create(
table, catalogReader, child, operation, updateColumnList,
sourceExpressionList, flattened
)
}
override fun <T : Any?> asQueryable(queryProvider: QueryProvider?, schema:
SchemaPlus?, tableName: String?): Queryable<T> {
TODO()
}
override fun getExpression(schema: SchemaPlus?, tableName: String?, clazz:
Class<*>?): Expression {
return Schemas.tableExpression(schema, elementType, tableName, clazz)
}
}
// from avatica
val conn = DriverManager.getConnection("jdbc:calcite:")
val calciteConn = conn.unwrap(CalciteConnection::class.java)
calciteConn.rootSchema.add("test", table)
calciteConn.createStatement().use { statement ->
statement.execute("""UPDATE "test" SET "foo" = 10 WHERE "foo" = 1""")
}
{code}
This is Kotlin code, I can rewrite it to Java if you need. There are many
things not implemented, but the exception from the issue happens before them.
This is the way to implement a table, that can be modified, if I understand
correctly.
> UPDATE doesn't work
> -------------------
>
> Key: CALCITE-2748
> URL: https://issues.apache.org/jira/browse/CALCITE-2748
> Project: Calcite
> Issue Type: Bug
> Components: avatica, core, jdbc-adapter
> Affects Versions: 1.17.0
> Reporter: Alexander Shilov
> Priority: Major
>
> I tried to use UPDATE DML statements, but got exception:
> {code:java}
> java.lang.AssertionError: UPDATE
> at
> org.apache.calcite.adapter.enumerable.EnumerableTableModify.implement(EnumerableTableModify.java:137)
> at
> org.apache.calcite.adapter.enumerable.EnumerableRelImplementor.implementRoot(EnumerableRelImplementor.java:100)
> at
> org.apache.calcite.adapter.enumerable.EnumerableInterpretable.toBindable(EnumerableInterpretable.java:92)
> at
> org.apache.calcite.prepare.CalcitePrepareImpl$CalcitePreparingStmt.implement(CalcitePrepareImpl.java:1238)
> at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:332)
> at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:231)
> at
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:772)
> at
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:636)
> at
> org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:606)
> at
> org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:229)
> at
> org.apache.calcite.jdbc.CalciteConnectionImpl.prepareStatement_(CalciteConnectionImpl.java:211)
> at
> org.apache.calcite.jdbc.CalciteConnectionImpl.prepareStatement(CalciteConnectionImpl.java:200)
> at
> org.apache.calcite.jdbc.CalciteConnectionImpl.prepareStatement(CalciteConnectionImpl.java:91)
> at
> org.apache.calcite.avatica.AvaticaConnection.prepareStatement(AvaticaConnection.java:175)
> ...{code}
> The reason is that EnumerableTableModify.implement doesn't support UPDATE.
> I've tried to implement it, but it's difficult with [Collection
> API|https://github.com/apache/calcite/blob/02752fe78f817ed317b8873d2f4c7b79bfe8b9b5/core/src/main/java/org/apache/calcite/schema/ModifiableTable.java#L40].
> There is no method in Collection, that can handle it, and if you use
> remove/add methods to simulate update, then updated rows count will be equals
> to zero.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)