我有一个cassandra表,其中包含一个名为snapshot的文本字段,其中包含JSON对象:
[identifier, timestamp, snapshot]
Run Code Online (Sandbox Code Playgroud)
我明白为了能够使用Spark对该字段进行转换,我需要将该RDD的该字段转换为另一个RDD以对JSON模式进行转换.
那是对的吗?我应该怎么做呢?
编辑:现在我设法从单个文本字段创建一个RDD:
val conf = new SparkConf().setAppName("signal-aggregation")
val sc = new SparkContext(conf)
val sqlContext = new SQLContext(sc)
val snapshots = sc.cassandraTable[(String, String, String)]("listener", "snapshots")
val first = snapshots.first()
val firstJson = sqlContext.jsonRDD(sc.parallelize(Seq(first._3)))
firstJson.printSchema()
Run Code Online (Sandbox Code Playgroud)
这向我展示了JSON架构.好!
我如何告诉Spark应该在表Snapshots的所有行上应用此模式,以便从每一行获取该快照字段的RDD?
我试图通过URLConnection获得最低级别的字节计数.我已经计算了两个流传递的数据,使用来自Apache Commons IO的CountingInputStream和CountingOutputStream,但是我得到的字节数等于我发送的正文大小+我收到的响应正文大小.
在HttpClient中,我有一个MeasuringClientConnManager,我认为它是一个更低级别的字节计数.
为了获得最准确的值,我使用TrafficStats将这些库的计数与这些方法进行比较:
public static long getCurrentRx(Context context){
int uid = context.getApplicationInfo().uid;
return TrafficStats.getUidRxBytes(uid);
}
public static long getCurrentTx(Context context){
int uid = context.getApplicationInfo().uid;
return TrafficStats.getUidTxBytes(uid);
}
public static long getCurrentNetworkUsage(Context context){
return getCurrentRx(context) + getCurrentTx(context);
}
public static long getDiffNetworkUsage(Context context, long previousNetworkUsage){
return getCurrentNetworkUsage(context) - previousNetworkUsage;
}
Run Code Online (Sandbox Code Playgroud)
使用这些方法,我获得了比使用HttpClient更接近URLConnection的值.
两个问题:
怎么来URLConnection,我没有在OutputStream上看到一些字节大小指示标题被发送?为什么我看到只有体型?标题在哪里?网址电话?DNS解析字节?
有没有办法测量URLConnection库调用在网络接口上发送的每个字节?最低级别越好!
Android资源中有一个Integer类型:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="bytes_size">2147483647</integer>
</resources>
Run Code Online (Sandbox Code Playgroud)
最大值为2147483647,那么我怎么能在其中拥有更大的价值呢?我是否必须将其作为String放置,然后将其转换为long类型,还是有更好的方法?
我有一个首先用Adobe Air创建的Android应用程序(及其生产密钥库).很久以前,该公司转而使用常规Android SDK开发应用程序,但由于该应用程序已投入生产,我们使用的密钥库仍然是相同的(由Adobe Air创建).
我使用keytool为Google Places API提取SHA1,我得到了以下内容:
Alias name: <alias_name>
Creation date: Jan 11, 2015
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
Owner: CN=<company_name>, OU=, O=, C=US
Issuer: CN=<company_name>, OU=, O=, C=US
Serial number: <lotsofnumbers>
Valid from: Mon Mar 28 14:08:17 IST 2011 until: Sat Mar 29 14:08:17 IDT 2036
Certificate fingerprints:
MD5: ..:8D:F7
SHA1: ..:E6:69
SHA256: ..:38:9A
Signature algorithm name: SHA1withRSA
Version: 3
Extensions:
#1: ObjectId: 2.5.29.37 Criticality=false
ExtendedKeyUsages [
codeSigning
]
Run Code Online (Sandbox Code Playgroud)
这个SHA1(由E6:69完成)从未在Google Places API中运行,因此我检查了apk包含的CERT.RSA,除了证书指纹外,它看起来几乎相同:
Valid from: Mon …Run Code Online (Sandbox Code Playgroud) 我有一个RDD包含一个名为time long类型的时间戳:
root
|-- id: string (nullable = true)
|-- value1: string (nullable = true)
|-- value2: string (nullable = true)
|-- time: long (nullable = true)
|-- type: string (nullable = true)
Run Code Online (Sandbox Code Playgroud)
我试图将value1,value2和time分组为YYYY-MM-DD.我试图按强制分组(时间为日期),但后来我收到以下错误:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.spark.deploy.worker.DriverWrapper$.main(DriverWrapper.scala:40)
at org.apache.spark.deploy.worker.DriverWrapper.main(DriverWrapper.scala)
Caused by: java.lang.RuntimeException: [1.21] failure: ``DECIMAL'' expected but identifier Date found
Run Code Online (Sandbox Code Playgroud)
这是否意味着没有办法按日期分组?我甚至试图添加另一个级别的转换以将其作为String:
cast(cast(time as Date) as String)
Run Code Online (Sandbox Code Playgroud)
哪个返回相同的错误.
我已经读过,我可能在RDD上使用了可能的aggregateByKey,但我不明白如何将它用于几列并将其转换为YYYY-MM-DD字符串.我该怎么办?
我正在使用Notification API开发RSS智能扩展应用程序.我想知道如何获得智能扩展的活动/非活动状态(在SmartWatch应用程序中单击我的RSS智能扩展时的第一个复选框).
NotificationAPI示例使用额外的Checkbox首选项来启动或不启动下载数据生成通知的服务,但我不想强迫用户进入子菜单并激活数据下载.如果用户激活我的RSS智能扩展,他已经预计扩展程序会通知他是否有一些新项目进入RSS.
有一个回调知道我的智能扩展程序何时正确添加到liveware/smartwatch应用程序(onRegisterResult),但我没有找到回调来知道智能扩展程序是否实际处于活动状态.
提前致谢!