我做了一个简单的UDF来转换或从spark中的temptabl中的时间字段中提取一些值.我注册了该函数,但是当我使用sql调用该函数时,它会抛出一个NullPointerException.以下是我的功能和执行过程.我正在使用Zeppelin.扼杀这是昨天工作,但它今天早上停止工作.
功能
def convert( time:String ) : String = {
val sdf = new java.text.SimpleDateFormat("HH:mm")
val time1 = sdf.parse(time)
return sdf.format(time1)
}
Run Code Online (Sandbox Code Playgroud)
注册功能
sqlContext.udf.register("convert",convert _)
Run Code Online (Sandbox Code Playgroud)
没有SQL测试函数 - 这是有效的
convert(12:12:12) -> returns 12:12
Run Code Online (Sandbox Code Playgroud)
在Zeppelin这个FAILS中用SQL测试函数.
%sql
select convert(time) from temptable limit 10
Run Code Online (Sandbox Code Playgroud)
结构的诱惑力
root
|-- date: string (nullable = true)
|-- time: string (nullable = true)
|-- serverip: string (nullable = true)
|-- request: string (nullable = true)
|-- resource: string (nullable = true)
|-- protocol: integer (nullable = true)
|-- sourceip: …
Run Code Online (Sandbox Code Playgroud) 我是Apache Spark的新手,我创建了几个RDD和DataFrames,缓存它们,现在我想通过使用下面的命令来解决它们中的一些问题
rddName.unpersist()
Run Code Online (Sandbox Code Playgroud)
但我不记得他们的名字.我使用sc.getPersistentRDDs
但输出不包括名称.我还使用浏览器查看缓存的rdds,但同样没有名称信息.我错过了什么吗?
我试图使用多线程方法运行一些查询,但我认为我做错了,因为我的程序需要大约五分钟来运行一个简单的选择语句,如
SELECT * FROM TABLE WHERE ID = 123'
Run Code Online (Sandbox Code Playgroud)
我的实现如下,我正在使用一个连接对象.
在我的run方法中
public void run() {
runQuery(conn, query);
}
Run Code Online (Sandbox Code Playgroud)
runQuery方法
public void runQuery(Connection conn, String queryString){
Statement statement;
try {
statement = conn.createStatement();
ResultSet rs = statement.executeQuery(queryString);
while (rs.next()) {}
} catch (SQLException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
最后在main方法中,我使用下面的代码片段启动线程.
MyThread bmthread = new MyThread(conn, query);
ArrayList<Thread> allThreads = new ArrayList<>();
double start = System.currentTimeMillis();
int numberOfThreads = 1;
for(int i=0; i<=numberOfThreads; i++){
Thread th = new Thread(bmthread);
th.setName("Thread "+i);
System.out.println("Starting Worker …
Run Code Online (Sandbox Code Playgroud) 我使用下面的代码成功删除了表格中的记录.我唯一的问题是,我希望它在删除之前提示用户确认操作.
{{link_to_route('individualprofiles.edit', 'Edit', array($ip->id))}}
{{Form::open(array( 'route' => array( 'individualprofiles.destroy', $ip->id ), 'method' => 'delete', 'style' => 'display:inline'))}}
{{Form::submit('D', array('class' => 'btn btn-danger'))}}
{{Form::close()}}
Run Code Online (Sandbox Code Playgroud) 我将以下行存储在HBase表中
DIEp(^o^)q3 column=DIE:ID, timestamp=1346194191174, value=\x00\x00\x00\x01
Run Code Online (Sandbox Code Playgroud)
我试图访问该值并将其转换为应该是的字符串表示形式1
,但是当我cat
将此文件(我的输出重定向到)时,我没有得到正确的字符串表示形式
cat /hadoop/logs/userlogs/job_201209121654_0027/attempt_201209121654_0027_m_000000_0/stdout
Run Code Online (Sandbox Code Playgroud)
我有类似垃圾的东西 NUL NUL NUL SOH
下面是我正在使用的代码片段.
byte[] result1 = value.getValue("DIE".getBytes(), "ID".getBytes());
String myresult = Bytes.toString(result1);
System.out.println(myresult);
Run Code Online (Sandbox Code Playgroud) 我有在SML两个列表,可以说,名单A [(a,b,c),(d,e,f)]
和B名单[b,e]
.我想计算B中与B中每个三元组的第二个元素匹配的每个项目的出现次数.输出应该是2.因为b
并且e
每个在A中出现一次.
到目前为止这是我的代码,但是当我从B中的一个元素移动到另一个元素时,我的计数器总是设置为0.我知道在Java中这只是一个简单的双循环.
fun number_in_months (d : (int * int * int ) list, m : (int) list) =
if null m then 0
else if null d then number_in_months(d, tl m)
else if (#2(hd d)) = (hd m) then 1 + number_in_months (tl d, m)
else number_in_months(tl d, m)
Run Code Online (Sandbox Code Playgroud) 我试图在Ubuntu 12.04上启用XSL,但它失败了.我在我的Ubuntu 13.04本地做了这个并且它成功了.基本上以下工作在我的本地计算机上.
我在运行的生产服务器Ubuntu 12.04
和PHP版本5.5.12 上重复了相同的过程,但是没有从phpinfo加载扩展.我也改变了extension=php5_xsl.so
,extension=xsl.so
因为这是扩展目录中的内容.
我读到我可能需要重新编译PHP,但我不确定这些步骤.
我试图基于搜索键在Individualprofile模型中搜索记录.从浏览器查看时,下面的路由会引发Call to undefined method Illuminate\Database\Eloquent\Collection::whereRaw()
异常.
在foreach循环内部我尝试Individualprofile::whereRaw(..)
但仍然是同样的问题.
以下是我的完整路线实施.
Route::get('/get-individualprofiles',function(){
$text = "Lamin";
if(trim($text) == ""){
return Individualprofile::take(10)->get();
}
$substr = preg_split("/[\s,.()&;:_-]+/",preg_replace("/(\w+)/","%$1%",trim($text)),-1,PREG_SPLIT_NO_EMPTY);
$profiles = Individualprofile::all();
foreach ($substr as $key) {
$profiles = $profiles->whereRaw('(name like ? or mobile like ? or address like ? or occupation like ? or mstatus like ?)',[$key,$key,$key,$key,$key]);
}
return $profiles->take(100)->get();
});
Run Code Online (Sandbox Code Playgroud) 我有以下表格模式,我想获得每个类别的金额列的总和以及相应类别中的雇员数量.
雇员
id | name | category
1 | SC | G 1.2
2 | BK | G 2.2
3 | LM | G 2.2
Run Code Online (Sandbox Code Playgroud)
payroll_histories
id | employee_id | amount
1 | 1 | 1000
2 | 1 | 500
3 | 2 | 200
4 | 2 | 100
5 | 3 | 300
Run Code Online (Sandbox Code Playgroud)
输出表应如下所示:
category | total | count
G 1.2 | 1500 | 1
G 2.2 | 600 | 2
Run Code Online (Sandbox Code Playgroud)
我在下面总结和分组时尝试了这个查询,但我无法让计数工作.
SELECT
employee_id,
category,
SUM(amount) …
Run Code Online (Sandbox Code Playgroud)