任何人都可以解释如何在设计带有一些示例的表时实现一对一,一对多和多对多的关系吗?
这是我的JSON字符串:
{"attributes":[{"nm":"ACCOUNT","lv":[{"v":{"Id":null,"State":null},"vt":"java.util.Map","cn":1}],"vt":"java.util.Map","status":"SUCCESS","lmd":13585},{"nm":"PROFILE","lv":[{"v":{"Party":null,"Ads":null},"vt":"java.util.Map","cn":2}],"vt":"java.util.Map","status":"SUCCESS","lmd":41962}]}
Run Code Online (Sandbox Code Playgroud)
我需要将上面的JSON String转换为Pretty Print JSON Output(使用Jackson),如下所示:
{
"attributes": [
{
"nm": "ACCOUNT",
"lv": [
{
"v": {
"Id": null,
"State": null
},
"vt": "java.util.Map",
"cn": 1
}
],
"vt": "java.util.Map",
"status": "SUCCESS",
"lmd": 13585
},
{
"nm": "PROFILE
"lv": [
{
"v": {
"Party": null,
"Ads": null
},
"vt": "java.util.Map",
"cn": 2
}
],
"vt": "java.util.Map",
"status": "SUCCESS",
"lmd": 41962
}
]
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以根据我上面的例子给我一个例子吗?如何实现这种情况?我知道有很多例子,但我无法正确理解这些例子.通过一个简单的例子可以获得任何帮助.
更新:
以下是我使用的代码:
ObjectMapper mapper = new ObjectMapper();
System.out.println(mapper.defaultPrettyPrintingWriter().writeValueAsString(jsonString));
Run Code Online (Sandbox Code Playgroud)
但这不适用于我需要输出的方式,如上所述.
这是我用于上述JSON的POJO:
public class UrlInfo implements …Run Code Online (Sandbox Code Playgroud) 我收到这个错误 -
不能访问类型为GeoLocation的封闭实例.必须使用GeoLocation类型的封闭实例限定分配(egxnew A(),其中x是GeoLocation的实例).这个错误出现在新的ThreadTask(i)上.我不知道为什么会这样.任何建议将不胜感激.
public class GeoLocation {
public static void main(String[] args) throws InterruptedException {
int size = 10;
// create thread pool with given size
ExecutorService service = Executors.newFixedThreadPool(size);
// queue some tasks
for(int i = 0; i < 3 * size; i++) {
service.submit(new ThreadTask(i));
}
// wait for termination
service.shutdown();
service.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
}
class ThreadTask implements Runnable {
private int id;
public ThreadTask(int id) {
this.id = id;
}
public void run() { …Run Code Online (Sandbox Code Playgroud) 如何从命令提示符中找到我正在使用的Hive版本.以下是详情 -
我使用Putty连接到hive表并访问表中的记录.所以我做的是 - 我打开Putty并输入我输入的主机名 - leo-ingesting.vip.name.com然后点击Open.然后我输入了我的用户名和密码,然后输入了很少的命令来访问Hive sql.以下是我所做的清单
$ bash
bash-3.00$ hive
Hive history file=/tmp/rkost/hive_job_log_rkost_201207010451_1212680168.txt
hive> set mapred.job.queue.name=hdmi-technology;
hive> select * from table LIMIT 1;
Run Code Online (Sandbox Code Playgroud)
那么从命令提示符是否有任何方法我可以找到我正在使用的Hive版本和Hadoop版本?
我写了一个下面的Singleton类.我不确定这是否是线程安全的单例类?
public class CassandraAstyanaxConnection {
private static CassandraAstyanaxConnection _instance;
private AstyanaxContext<Keyspace> context;
private Keyspace keyspace;
private ColumnFamily<String, String> emp_cf;
public static synchronized CassandraAstyanaxConnection getInstance() {
if (_instance == null) {
_instance = new CassandraAstyanaxConnection();
}
return _instance;
}
/**
* Creating Cassandra connection using Astyanax client
*
*/
private CassandraAstyanaxConnection() {
context = new AstyanaxContext.Builder()
.forCluster(ModelConstants.CLUSTER)
.forKeyspace(ModelConstants.KEYSPACE)
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
.setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
)
.withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
.setPort(9160)
.setMaxConnsPerHost(1)
.setSeeds("127.0.0.1:9160")
)
.withAstyanaxConfiguration(new AstyanaxConfigurationImpl()
.setCqlVersion("3.0.0")
.setTargetCassandraVersion("1.2"))
.withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
.buildKeyspace(ThriftFamilyFactory.getInstance());
context.start();
keyspace = context.getEntity();
emp_cf = …Run Code Online (Sandbox Code Playgroud) 我的shell脚本中有以下代码,如果找不到任何文件,它将继续处于休眠状态.它睡了半个小时,但目前我没有任何计数器,如只执行下面的代码20次然后退出程序,如果文件仍然不存在(意味着在20次检查后不做任何事情并退出完整的脚本).
解决这个问题的最佳方法是什么?通过查看已经尝试过20次的电子邮件,我也知道了.
希望我足够清楚.
while true; do
if /home/hadoop/latest/bin/hadoop fs -ls /apps/hdtech/bds/quality-rt/dt=$DATE_YEST_FORMAT2 then
echo "Files Present" | mailx -s "File Present" -r admin@host.com admin@host.com
break
else
echo "Sleeping for half an hour" | mailx -s "Time to Sleep Now" -r admin@host.com admin@host.com
sleep 1800
fi
done
Run Code Online (Sandbox Code Playgroud) 我最近开始使用Cassandra数据库.现在我正在评估Cassandra client我们应该推进哪些方面.
我已经在stackoverflow上看到关于哪个客户端用于Cassandra的各种帖子,但没有一个有非常确定的答案.
我的团队已经让我对此进行一些研究,并pros and cons为Cassandra Client API’sJava中的每一个做出一定的研究.
正如我所提到的,我最近参与其中,Cassandra所以没有那么多想法为什么某些人选择Pelops client以及为什么某些人和Astyanax其他客户一起去.
我知道每个Cassandra客户的简短介绍,我的意思是我能够完成这项工作并开始阅读和写入Cassandra数据库.
以下是我到目前为止的信息.
CASSANDRA APIS
Hector(Production-Ready)
最稳定的Java API,为黄金时段做好准备.
Astyanax(The Up and Comer)
来自Netflix的干净Java API.它没有Hector广泛使用,但它是坚实的.
符合JPA标准的Kundera(NoSQL ORM),当您想通过对象与Cassandra进行交互时,这很方便.
这在一定程度上限制了您将无法拥有动态数量的列/名称等.但它确实允许您移植到ORM,或将存储集中到Cassandra以获得更多传统用途.
Pelops
我只是简单地使用了Pelops.这是一个直接的API,但似乎没有它背后的动力.
PlayORM(没有约束的ORM?)
我刚才听说过这个.看起来它试图通过引入JQL来解决传统的基于JPA的ORM和NoSQL之间的阻抗不匹配问题.看起来很有希望.
节俭(避免我!)
这是"低级"API.
以下是我们决定的优先事项Cassandra Client-
任何人都可以对此提出一些想法吗?此外,每个Cassandra Client客户都可以满足我的要求的任何利弊也将有很大的帮助.
我相信,主要是我将围绕着Astyanax client or New Datastax client that uses Binary protocol我的研究基础到目前为止.但是没有某些信息可以支持我的研究并将其呈现给我的团队.
Astyanax客户端和New Datastax客户端(使用新的二进制协议)之间的任何比较都将有很大帮助.
这对我的研究有很大的帮助,并且会从过去使用不同客户的不同人那里获得很多相关知识.
这是下面的Hive表
CREATE EXTERNAL TABLE IF NOT EXISTS SampleTable
(
USER_ID BIGINT,
NEW_ITEM ARRAY<STRUCT<PRODUCT_ID: BIGINT,TIMESTAMPS:STRING>>
)
Run Code Online (Sandbox Code Playgroud)
这是上表中的数据 -
1015826235 [{"product_id":220003038067,"timestamps":"1340321132000"},{"product_id":300003861266,"timestamps":"1340271857000"}]
Run Code Online (Sandbox Code Playgroud)
有什么办法可以在爆炸阵列后从HiveQL获得以下输出吗?
**USER_ID** | **PRODUCT_ID** | **TIMESTAMPS**
------------+------------------+----------------
1015826235 220003038067 1340321132000
1015826235 300003861266 1340271857000
Run Code Online (Sandbox Code Playgroud)
更新
我写了这个查询以获得上述格式的输出,但它并没有按照我想要的方式给出结果.
SELECT myTable1.myCol1,myTable2.myCol2 FROM sampletable st LATERAL VIEW
explode(st.purchased_item.product_id) myTable1 AS myCol1 LATERAL VIEW
explode(st.purchased_item.timestamps) myTable2 AS myCol2;
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我解决我的错误吗?任何建议将不胜感激.
我通过传递ipAddress来调用方法,它将返回ipAddress的位置,如Country,City等等.所以我试图看看它为每次调用花了多少时间.所以我在调用方法之前设置了start_time,在调用之后设置了end_time.所以有时我会得到0的差异.并且resp包含有效的响应.
long start_time = System.currentTimeMillis();
resp = GeoLocationService.getLocationIp(ipAddress);
long end_time = System.currentTimeMillis();
long difference = end_time-start_time;
Run Code Online (Sandbox Code Playgroud)
所以这意味着有时需要0毫秒来获得响应.任何建议将不胜感激.
我试图通过在jsp中编写一些代理代码,从我的计算机本地对其他域进行ajax调用.这是我调用proxy.jsp页面的jQuery AJAX代码.
var metadata = 'https://rest-search.host.com/machine/search/meta?id=';
var on_show_info= function() {
var AjaxCall = data + current_doc_info.id;
alert(AjaxCall);
request_meta_info = $.ajax({
url: "proxy.jsp?url=" + AjaxCall,
type: 'GET',
success: check,
error: error
});
};
Run Code Online (Sandbox Code Playgroud)
我的JSP文件是: -
<%@ page language="java" import="org.w3c.dom.*,javax.xml.parsers.DocumentBuilder,javax.xml.parsers.DocumentBuilderFactory,java.net.*,java.io.*" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%
String urlToQuery = request.getParameter("url");
System.out.println("rj " +urlToQuery);
URL url = new URL(urlToQuery);
final String login ="user";
final String password ="pass";
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication (login, password.toCharArray());
}
});
URLConnection conn = url.openConnection(); …Run Code Online (Sandbox Code Playgroud)