我在AWS上有一个集群,有2个从属和1个主服务器.所有实例都是m1.large类型.我正在运行Spark 1.4版本.我正在对来自红移的4米数据的火花性能进行基准测试.我通过pyspark shell发出了一个查询
df = sqlContext.load(source="jdbc", url="connection_string", dbtable="table_name", user='user', password="pass")
df.registerTempTable('test')
d=sqlContext.sql("""
select user_id from (
select -- (i1)
sum(total),
user_id
from
(select --(i2)
avg(total) as total,
user_id
from
test
group by
order_id,
user_id) as a
group by
user_id
having sum(total) > 0
) as b
"""
)
Run Code Online (Sandbox Code Playgroud)
当我执行d.count()时,上面的查询在df未缓存时需要30秒,df在内存中缓存时需要17秒.
我期待这些时间接近1-2秒.
这些是我的火花配置:
spark.executor.memory 6154m
spark.driver.memory 3g
spark.shuffle.spill false
spark.default.parallelism 8
Run Code Online (Sandbox Code Playgroud)
rest设置为默认值.任何人都能看到我在这里失踪的东西吗?
还有其他更好的方法来填充数组:
var arr = [];
var i = 0;
$('select').children('option').each( function() {
arr[i++] = $(this).html();
});
Run Code Online (Sandbox Code Playgroud) 我正在尝试获取客户端到达日期并将其与我的SQL数据库进行比较,以查看在我的数据库中是否存在相同的日期.但是我收到以下错误:The operator > is undefined for the argument type(s) java.lang.String, java.lang.String
PS我需要通过java比较它而不是使用sql查询
public void makeNewReservation() throws ParseException {
// Enter informations
System.out.println("Date of arrivel?");
Scanner in = new Scanner(System.in);
String date_entree = in.next();
System.out.println("Date of exit? dd/MM/yyyy");
String date_sortiee = in.next();
calculateDaysDifference(date_sortiee, date_entree);
public void calculateDaysDifference(String date_entree, String date_sortiee) throws ParseException{
ConnectionMySQL myConnection=new ConnectionMySQL();
Connection conSQL=myConnection.startDBConnection();
boolean connectionOK=myConnection.checkConnection(conSQL);
String query = ("SELECT `START_DATE`,`END_DATE` FROM `room_booking");
//if everything is fine with the connection, i try to execute a query
if …Run Code Online (Sandbox Code Playgroud) 我需要通过指针交换两个字符,但是运行此代码时,程序崩溃。
int main(){
char *s1 = "string1";
swap(st,(st+1));
/* BUT THIS CODE WORKS - Whats the problem?
* char s1[] = "string1";
* swap(s1,&s1[1]);
*/
return 0;
}
void swap(char * const ptr1, char * const ptr2){
char temp = *ptr1;
*ptr1 = *ptr2;
*ptr2 = temp;
}
Run Code Online (Sandbox Code Playgroud) 我有Item和Sales表,有不同的列,比如
项目
ItemName
Itemcost
ItemQty
Run Code Online (Sandbox Code Playgroud)
销售
SalesName
SalesDate
SalesQty
Run Code Online (Sandbox Code Playgroud)
在上面的表中没有常见的列,但我需要输出为
ItemName,ItemCost,SalesName,SalesDate.
Run Code Online (Sandbox Code Playgroud)
我试过工会,
select ItemName,ItemCost from Item
union
select SalesName,SalesDate from Sales
Run Code Online (Sandbox Code Playgroud)
但我只获得了一个像ItemName,ItemCost这样的表列
请帮我解决这个问题
提前致谢
Venkat.
我有以下代码
set x=%date /T %
date 16/12/2012
date 15/12/2012
some stuff goes here
echo set your date
date %x% <--- getting error in that line.
pause
Run Code Online (Sandbox Code Playgroud)
那么我怎样才能以dd/mm/yy的格式得到日期
void fun(int* array){}
int main(){
int array[]={1,2,3};
fun(&array);----->(1)//error in this line
return 0;
}
Run Code Online (Sandbox Code Playgroud)
error: cannot convert âint (*)[3]â to âint*â for argument â1â to âvoid fun(int*â).
如果我通过fun(&array[0]),它的工作正常.按照我的理解&array,&array[0]两者都产生相同的地址.明确澄清.
我想将输入流写入java中的文件.如何将内容写入java中的文本文件?
try {
BufferedReader in = new BufferedReader(new
InputStreamReader(client.getInputStream()));
//I want to write the content to a file line by line here
while (!in.ready()) {}
System.out.print("'\n");
in.close();
}
Run Code Online (Sandbox Code Playgroud) 为什么此代码打印1而不是5
码:
main(int x=5) //this defn. is written intentionally to chec weather main accepts
expression or not.
{
printf("%d",x);
}
Run Code Online (Sandbox Code Playgroud)
编译使用:minGW 3.2
编辑
我的观点是天气x=5执行与否.如果没有那么为什么我没有得到任何错误或警告.
我有一个矢量:
std::vector<Edge> edges(num);
Run Code Online (Sandbox Code Playgroud)
最后包含空单元格,我想用lambda删除但是当我这样做时:
edges.erase(std::remove_if(edges.begin(), edges.end(),
std::mem_fn(&std::Edge::empty), edges.end() );
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误:
error C2664: 'bool main::<lambda_6f33349b59d49f69703a5fa6a8c5995a>::operator ()(const std::vector<_Ty> &) const' : cannot convert parameter 1 from 'Edge' to 'const std::vector<_Ty> &'
Run Code Online (Sandbox Code Playgroud)
现在我该怎么做?
三年前我学习了C编程语言,现在当我在java和c#面对一些指针问题之后重新访问它时.所以我试着写一个简单的矩阵添加程序,但我不知道为什么我在打印矩阵时会得到一些奇怪的值.
码:
#include <stdio.h>
int* sumOfMat(int* m1,int* m2)
{
printf("Matrix A: \n");
printMat(m1);
printf("Matrix B: \n");
printMat(m2);
int mat3[3][3];
int row=0,col=0,k=0,sum=0;
for(;row<3;row++)
{
col=0;
for (;col<3 ;col++ )
{
sum=(*m1+*m2);
m1++;
m2++;
mat3[row][col]=sum;
}
}
printf("Result: \n");
// printMat(mat3); //this statement is giving me a correct output.
return mat3;
}
void printMat(const int m[3][3])
{
int row,col;
for (row=0;row<3 ;row++ )
{
for (col=0;col<3 ;col++ )
{
printf("%d\t",m[row][col]);
}
printf("\n");
}
}
int main(void) {
int mat1[3][3]={{1,2,3},{4,5,6},{7,8,9}};
int mat2[3][3]={{1,2,3},{4,5,6},{7,8,9}};
//add …Run Code Online (Sandbox Code Playgroud) 这是我的代码,除了无限循环之外几乎正常工作 printInTree()
struct node{
char text[100];
int count;
struct node* left;
struct node* right;
};
struct node* addNode(struct node* n,char w[]){
int cond=0;
if(n == NULL){
n=malloc(sizeof(struct node));
n->count=1;
n->left=NULL;
n->right=NULL;
strcpy(n->text,w);
}
else if((cond=strcmp(w,n->text))==0){
n->count++;
}
else if(cond>0){
n->right=addNode(n->right,w);
}
else{
n->left=addNode(n->left,w);
}
return n;
};
void printInTree(struct node* p){
while(p != NULL){ //infinite loop here.
printInTree(p->left);
printf("%3s - %d\n",p->text,p->count);
printInTree(p->right);
}
}
void b_treeDemo(){
struct node *root=NULL;
FILE* f=fopen("main.c","r");
char word[100];
while(1){
if(getWord(f,word)>0){
if(isalpha(word[0])){
root=addNode(root,word);
}
}else{
break; …Run Code Online (Sandbox Code Playgroud) 解决以下练习:
编写三个不同版本的程序来打印ia的元素.一个版本应该使用一个范围来管理迭代,另外两个应该在一个案例中使用普通的for循环使用下标,而在另一个案例中使用指针.在所有三个程序中直接编写所有类型.也就是说,不要使用类型别名,auto或decltype来简化代码.[C++ Primer]
一个问题出现了:这些访问阵列的方法在速度和原因方面都得到了优化?
我的解决方案
Foreach循环:
int ia[3][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};
for (int (&i)[4]:ia) //1st method using for each loop
for(int j:i)
cout<<j<<" ";
Run Code Online (Sandbox Code Playgroud)嵌套for循环:
for (int i=0;i<3;i++) //2nd method normal for loop
for(int j=0;j<4;j++)
cout<<ia[i][j]<<" ";
Run Code Online (Sandbox Code Playgroud)使用指针:
int (*i)[4]=ia;
for(int t=0;t<3;i++,t++){ //3rd method. using pointers.
for(int x=0;x<4;x++)
cout<<(*i)[x]<<" ";
Run Code Online (Sandbox Code Playgroud)使用auto:
for(auto &i:ia) //4th one using auto but I think it is similar to 1st.
for(auto j:i)
cout<<j<<" ";
Run Code Online (Sandbox Code Playgroud)使用基准测试结果 clock()
1st: 3.6 (6,4,4,3,2,3)
2nd: 3.3 (6,3,4,2,3,2)
3rd: 3.1 (4,2,4,2,3,4) …Run Code Online (Sandbox Code Playgroud) c++ ×4
c ×3
pointers ×3
arrays ×2
c++11 ×2
java ×2
sql ×2
apache-spark ×1
batch-file ×1
binary-tree ×1
char ×1
cmd ×1
io ×1
jquery ×1
matrix ×1
optimization ×1
pyspark ×1
streaming ×1
vector ×1