如何从aerospike命名空间获取所有键,就像我可以从地图中获取键一样map.keyset.我经历了这个链接Aerospike:我如何获得记录密钥?.我做了答案中被告知的事情.我编写了代码,writePolicy.sendKey = true但是NULL当我在scanCallback功能中显示密钥时,我仍然会得到.
这是我写一条记录的代码(任何帮助将不胜感激)
def writeToAerospike(): Boolean = {
val host:Host = new Host("xx.xxx.xxx.xx", 3000)
val client = new AerospikeClient(new ClientPolicy,host)
val policy = new WritePolicy();
policy.sendKey = true;
policy.timeout = 50000;
if(client.isConnected()){
println("connection to aerospike client sucessful")
client.put(policy,new Key("test", "testSet", "1"),new Bin("name", "john"))
//verify if the record is entered correctly
println(client.get(policy,new Key("test", "testing", "1")).getValue("name"))
client.close()
return true
}
return false
}
Run Code Online (Sandbox Code Playgroud)
我使用此示例中的代码来扫描记录:http://www.aerospike.com/docs/client/java/usage/scan/scan.html
class ScanParallelTest …Run Code Online (Sandbox Code Playgroud) 我是 Spark 新手,正在使用 scala 进行编码。我想从 HDFS 或 S3 读取文件并将其转换为 Spark 数据帧。Csv 文件的第一行是架构。但是如何创建一个具有未知列的架构的数据框?我使用以下代码为已知模式创建数据框。
def loadData(path:String): DataFrame = {
val rdd = sc.textFile(path);
val firstLine = rdd.first();
val schema = StructType(firstLine.split(',').map(fieldName=>StructField(fieldName,StringType,true)));
val noHeader = rdd.mapPartitionsWithIndex(
(i, iterator) =>
if (i == 0 && iterator.hasNext) {
iterator.next
iterator
} else iterator)
val rowRDD = noHeader.map(_.split(",")).map(p => Row(p(0), p(1), p(2), p(3), p(4),p(5)))
val dataFrame = sqlContext.createDataFrame(rowRDD, schema);
return dataFrame;
Run Code Online (Sandbox Code Playgroud)
}
aerospike ×1
apache-spark ×1
csv ×1
dataframe ×1
get ×1
hdfs ×1
key ×1
namespaces ×1
record ×1
scala ×1