dynamodb:tried to access class com.amazonaws.services.dynamodbv2.document.internal.IteratorSupport
2017-09-16 22:25
597 查看
查询dynamodb表数据:
val tableName = "mytable"
当用QuerySpec查询dynamodb 表用iterator遍历时,如果是在java环境下,不会报下面错误,但是在scala环境下,就会报下面错误,主要还是包的访问权限造成的
解决办法:可采用dynamodb mapper方式接口进行查询,或者用QueryRequest方式:
val tableName = "mytable"
val table = new Table(DynamoDBClientUtil.getDynamoDBClient, tableName) val conditionAllQuery = new StringBuilder() .append("record_key").append("=").append(":record_key") .append(" and #timestamp > :timestamp") .toString() val querySpec = new QuerySpec() .withKeyConditionExpression(conditionAllQuery) .withConsistentRead(true) .withNameMap(new NameMap().`with`("#timestamp", "timestamp")) .withValueMap(new ValueMap() .withString(":record_key", "mykey") .withLong(":timestamp", "mytime".toLong)) val iterator = table.query(querySpec).iterator() while (iterator.hasNext){ println(iterator.next()) }
当用QuerySpec查询dynamodb 表用iterator遍历时,如果是在java环境下,不会报下面错误,但是在scala环境下,就会报下面错误,主要还是包的访问权限造成的
Exception in thread "main" java.lang.IllegalAccessError: tried to access class com.amazonaws.services.dynamodbv2.document.internal.IteratorSupport from class
解决办法:可采用dynamodb mapper方式接口进行查询,或者用QueryRequest方式:
val expressionAttributesNames = new util.HashMap[String,String]() expressionAttributesNames.put("#record_key","record_key"); expressionAttributesNames.put("#timestamp","timestamp"); val expressionAttributeValues = new util.HashMap[String,AttributeValue]() expressionAttributeValues.put(":record_key",new AttributeValue().withS("mykey")); expressionAttributeValues.put(":timestamp",new AttributeValue().withN("mytime")); val query = new QueryRequest() .withTableName(tableName) .withKeyConditionExpression("#record_key = :record_key and #timestamp > :timestamp ") .withExpressionAttributeNames(expressionAttributesNames) .withExpressionAttributeValues(expressionAttributeValues); val queryResult = DynamoDBClientUtil.getDynamoDBClient.query(query).getItems
相关文章推荐
- Amazon DynamoDB应用—为table指定Provisioned Throughput
- DynamoDB中的二级索引(global secondary index)
- dynamodb使用文档(中英文,中文相对全一些)
- EMR+DynamoDB+Hive 15分钟入门
- 编写dynamodb基于GSI的分页查询
- dynamodb 基本操作
- Amazon DynamoDB的模型
- DynamoDB启动本地版本和python-sdk使用示例
- dynamodb 分区键排序键介绍
- Amazon AWS亚马逊云服务新服务简介(DynamoDB, Redshift,Kinesis)
- 连接AWS的DynamoDB例子(scala版)
- 新的免费教学视频和实验 - DynamoDB, Elastic Beanstalk 和 Elastic MapReduce 介绍
- boto3 dynamodb 入门使用
- Amazon DynamoDB简介(一)
- dynamoDB数据库
- DynamoDB了解(未完待续)
- js连接AWS DynamoDB数据库实现CEUD操作
- DynamoDB
- DynamoDB常见问题
- Aws Dynamodb数据导出到S3