ERROR: Phantom-dsl BatchQuery Unspecified with Overloaded method
ERROR: Phantom-dsl BatchQuery Unspecified with Overloaded method
我正在尝试扩展我的应用程序以包含另一个 Cassandra table 用于存储每个块中包含的交易。
我尽量使代码片段简洁且相关。如果需要进一步的代码上下文 - 请告诉我。
phantomVersion = "1.22.0"
cassandraVersion = "2.1.4"
我在使用下面列出的代码时遇到以下编译错误。非常感谢见解。
[error] /home/dan/projects/open-blockchain/scanner/src/main/scala/org/dyne/danielsan/openblockchain/data/database/Database.scala:30: overloaded method value add with alternatives:
[error] (batch: com.websudos.phantom.batch.BatchQuery[_])com.websudos.phantom.batch.BatchQuery[com.websudos.phantom.builder.Unspecified] <and>
[error] (queries: Iterator[com.websudos.phantom.builder.query.Batchable with com.websudos.phantom.builder.query.ExecutableStatement])(implicit session: com.datastax.driver.core.Session)com.websudos.phantom.batch.BatchQuery[com.websudos.phantom.builder.Unspecified] <and>
[error] (queries: com.websudos.phantom.builder.query.Batchable with com.websudos.phantom.builder.query.ExecutableStatement*)(implicit session: com.datastax.driver.core.Session)com.websudos.phantom.batch.BatchQuery[com.websudos.phantom.builder.Unspecified] <and>
[error] (query: com.websudos.phantom.builder.query.Batchable with com.websudos.phantom.builder.query.ExecutableStatement)(implicit session: com.datastax.driver.core.Session)com.websudos.phantom.batch.BatchQuery[com.websudos.phantom.builder.Unspecified]
[error] cannot be applied to (scala.concurrent.Future[com.datastax.driver.core.ResultSet])
[error] .add(ChainDatabase.bt.insertNewBlockTransaction(bt))
[error] ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 6 s, completed Aug 9, 2016 2:42:30 PM
GenericBlockModel.scala:
case class BlockTransaction(hash: String, txid: String)
sealed class BlockTransactionModel extends CassandraTable[BlockTransactionModel, BlockTransaction] {
override def fromRow(r: Row): BlockTransaction = {
BlockTransaction(
hash(r),
txid(r)
)
}
object hash extends StringColumn(this) with PartitionKey[String]
object txid extends StringColumn(this) with ClusteringOrder[String] with Descending
}
abstract class ConcreteBlockTransactionModel extends BlockTransactionModel with RootConnector {
override val tableName = "block_transactions"
def insertNewBlockTransaction(bt: BlockTransaction): Future[ResultSet] = insertNewRecord(bt).future()
def insertNewRecord(bt: BlockTransaction) = {
insert
.value(_.hash, bt.hash)
.value(_.txid, bt.txid)
}
}
Database.scala
class Database(val keyspace: KeySpaceDef) extends DatabaseImpl(keyspace) {
def insertBlock(block: Block) = {
Batch.logged
.add(ChainDatabase.block.insertNewRecord(block))
.future()
}
def insertTransaction(tx: Transaction) = {
Batch.logged
.add(ChainDatabase.tx.insertNewTransaction(tx))
.future()
}
def insertBlockTransaction(bt: BlockTransaction) = {
Batch.logged
.add(ChainDatabase.btx.insertNewBlockTransaction(bt))
.future()
}
object block extends ConcreteBlocksModel with keyspace.Connector
object tx extends ConcreteTransactionsModel with keyspace.Connector
object btx extends ConcreteBlockTransactionsModel with keyspace.Connector
}
object ChainDatabase extends Database(Config.keySpaceDefinition)
错误显然是您试图将Future
添加到Batch
,而Batch
需要查询。如果您已经触发了一个查询,则无法再对其进行批处理,因此您需要提前停止。方法如下:
def insertNewRecord(
bt: BlockTransaction
): InsertQuery.Default[BlockTransactionModel, BlockTransaction] = {
insert
.value(_.hash, bt.hash)
.value(_.txid, bt.txid)
}
现在您可以将多条记录添加到一个批次中:
Batch.logged.add(insertNewRecord(record1)
.add(insertNewRecord(record2))
// etc
换句话说,Cassandra 中的 batch
不用于并行插入,而是用于保证原子性,这使得它通常比普通并行插入至少慢 30%。阅读 this 了解更多详情。
如果你只是想同时插入更多的东西,你可以使用这样的方法returns一个未来:
def insertMany(
list: List[BlockTransaction]
): Future[List[ResultSet]] = {
Future.sequence(list.map(insertNewRecord(_).future()))
}
我正在尝试扩展我的应用程序以包含另一个 Cassandra table 用于存储每个块中包含的交易。
我尽量使代码片段简洁且相关。如果需要进一步的代码上下文 - 请告诉我。
phantomVersion = "1.22.0"
cassandraVersion = "2.1.4"
我在使用下面列出的代码时遇到以下编译错误。非常感谢见解。
[error] /home/dan/projects/open-blockchain/scanner/src/main/scala/org/dyne/danielsan/openblockchain/data/database/Database.scala:30: overloaded method value add with alternatives:
[error] (batch: com.websudos.phantom.batch.BatchQuery[_])com.websudos.phantom.batch.BatchQuery[com.websudos.phantom.builder.Unspecified] <and>
[error] (queries: Iterator[com.websudos.phantom.builder.query.Batchable with com.websudos.phantom.builder.query.ExecutableStatement])(implicit session: com.datastax.driver.core.Session)com.websudos.phantom.batch.BatchQuery[com.websudos.phantom.builder.Unspecified] <and>
[error] (queries: com.websudos.phantom.builder.query.Batchable with com.websudos.phantom.builder.query.ExecutableStatement*)(implicit session: com.datastax.driver.core.Session)com.websudos.phantom.batch.BatchQuery[com.websudos.phantom.builder.Unspecified] <and>
[error] (query: com.websudos.phantom.builder.query.Batchable with com.websudos.phantom.builder.query.ExecutableStatement)(implicit session: com.datastax.driver.core.Session)com.websudos.phantom.batch.BatchQuery[com.websudos.phantom.builder.Unspecified]
[error] cannot be applied to (scala.concurrent.Future[com.datastax.driver.core.ResultSet])
[error] .add(ChainDatabase.bt.insertNewBlockTransaction(bt))
[error] ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 6 s, completed Aug 9, 2016 2:42:30 PM
GenericBlockModel.scala:
case class BlockTransaction(hash: String, txid: String)
sealed class BlockTransactionModel extends CassandraTable[BlockTransactionModel, BlockTransaction] {
override def fromRow(r: Row): BlockTransaction = {
BlockTransaction(
hash(r),
txid(r)
)
}
object hash extends StringColumn(this) with PartitionKey[String]
object txid extends StringColumn(this) with ClusteringOrder[String] with Descending
}
abstract class ConcreteBlockTransactionModel extends BlockTransactionModel with RootConnector {
override val tableName = "block_transactions"
def insertNewBlockTransaction(bt: BlockTransaction): Future[ResultSet] = insertNewRecord(bt).future()
def insertNewRecord(bt: BlockTransaction) = {
insert
.value(_.hash, bt.hash)
.value(_.txid, bt.txid)
}
}
Database.scala
class Database(val keyspace: KeySpaceDef) extends DatabaseImpl(keyspace) {
def insertBlock(block: Block) = {
Batch.logged
.add(ChainDatabase.block.insertNewRecord(block))
.future()
}
def insertTransaction(tx: Transaction) = {
Batch.logged
.add(ChainDatabase.tx.insertNewTransaction(tx))
.future()
}
def insertBlockTransaction(bt: BlockTransaction) = {
Batch.logged
.add(ChainDatabase.btx.insertNewBlockTransaction(bt))
.future()
}
object block extends ConcreteBlocksModel with keyspace.Connector
object tx extends ConcreteTransactionsModel with keyspace.Connector
object btx extends ConcreteBlockTransactionsModel with keyspace.Connector
}
object ChainDatabase extends Database(Config.keySpaceDefinition)
错误显然是您试图将Future
添加到Batch
,而Batch
需要查询。如果您已经触发了一个查询,则无法再对其进行批处理,因此您需要提前停止。方法如下:
def insertNewRecord(
bt: BlockTransaction
): InsertQuery.Default[BlockTransactionModel, BlockTransaction] = {
insert
.value(_.hash, bt.hash)
.value(_.txid, bt.txid)
}
现在您可以将多条记录添加到一个批次中:
Batch.logged.add(insertNewRecord(record1)
.add(insertNewRecord(record2))
// etc
换句话说,Cassandra 中的 batch
不用于并行插入,而是用于保证原子性,这使得它通常比普通并行插入至少慢 30%。阅读 this 了解更多详情。
如果你只是想同时插入更多的东西,你可以使用这样的方法returns一个未来:
def insertMany(
list: List[BlockTransaction]
): Future[List[ResultSet]] = {
Future.sequence(list.map(insertNewRecord(_).future()))
}