This seem to be more a question of spark-sql shell? I may suggest you change the email title to get more attention.
________________________________ From: ya <xinxi...@126.com> Sent: Wednesday, June 5, 2019 11:48:17 PM To: user@spark.apache.org Subject: sparksql in sparkR? Dear list, I am trying to use sparksql within my R, I am having the following questions, could you give me some advice please? Thank you very much. 1. I connect my R and spark using the library sparkR, probably some of the members here also are R users? Do I understand correctly that SparkSQL can be connected and triggered via SparkR and used in R (not in sparkR shell of spark)? 2. I ran sparkR library in R, trying to create a new sql database and a table, I could not get the database and the table I want. The code looks like below: library(SparkR) Sys.setenv(SPARK_HOME='/Users/ya/Downloads/soft/spark-2.4.3-bin-hadoop2.7') sparkR.session(sparkHome=Sys.getenv('/Users/ya/Downloads/soft/spark-2.4.3-bin-hadoop2.7')) sql("create database learnsql; use learnsql") sql(" create table employee_tbl (emp_id varchar(10) not null, emp_name char(10) not null, emp_st_addr char(10) not null, emp_city char(10) not null, emp_st char(10) not null, emp_zip integer(5) not null, emp_phone integer(10) null, emp_pager integer(10) null); insert into employee_tbl values ('0001','john','yanlanjie 1','gz','jiaoqiaojun','510006','1353'); select*from employee_tbl; “) I ran the following code in spark-sql shell, I get the database learnsql, however, I still can’t get the table. spark-sql> create database learnsql;show databases; 19/06/06 14:42:36 INFO HiveMetaStore: 0: create_database: Database(name:learnsql, description:, locationUri:file:/Users/ya/spark-warehouse/learnsql.db, parameters:{}) 19/06/06 14:42:36 INFO audit: ugi=ya ip=unknown-ip-addr cmd=create_database: Database(name:learnsql, description:, locationUri:file:/Users/ya/spark-warehouse/learnsql.db, parameters:{}) Error in query: org.apache.hadoop.hive.metastore.api.AlreadyExistsException: Database learnsql already exists; spark-sql> create table employee_tbl > (emp_id varchar(10) not null, > emp_name char(10) not null, > emp_st_addr char(10) not null, > emp_city char(10) not null, > emp_st char(10) not null, > emp_zip integer(5) not null, > emp_phone integer(10) null, > emp_pager integer(10) null); Error in query: no viable alternative at input 'create table employee_tbl\n(emp_id varchar(10) not'(line 2, pos 20) == SQL == create table employee_tbl (emp_id varchar(10) not null, --------------------^^^ emp_name char(10) not null, emp_st_addr char(10) not null, emp_city char(10) not null, emp_st char(10) not null, emp_zip integer(5) not null, emp_phone integer(10) null, emp_pager integer(10) null) spark-sql> insert into employee_tbl values ('0001','john','yanlanjie 1','gz','jiaoqiaojun','510006','1353'); 19/06/06 14:43:43 INFO HiveMetaStore: 0: get_table : db=default tbl=employee_tbl 19/06/06 14:43:43 INFO audit: ugi=ya ip=unknown-ip-addr cmd=get_table : db=default tbl=employee_tbl Error in query: Table or view not found: employee_tbl; line 1 pos 0 Does sparkSQL has different coding grammar? What did I miss? Thank you very much. Best regards, YA --------------------------------------------------------------------- To unsubscribe e-mail: user-unsubscr...@spark.apache.org