This tutorial will show you how to use sqlContext in Spark SQL to create and drop tables. Please review the previous sessions on “Spark” to gain a better understanding of “Spark SQL” and “sqlContext.”
scala> sqlContext.sql(
“CREATE TABLE emp(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ‘,’
LINES TERMINATED BY ‘\n’
“);
If you want to create in the traditional SQL approach, use the following command.
scala> sqlContext.sql(
“CREATE TABLE emptest(
empno int,
ename string,
locid int)”
);
scala> sqlContext.sql(
“drop table emp”)
To avoid each line being executed, please type the above command in a single line as shown in the image.
Hope you find this article helpful.
Subscribing to this site will allow you to receive quick updates on future articles.