I was trying to load data from Oracle database using Spark data source API.
Since I need to load data by query, I used the query below which I put together from some examples online:
Map<String, String> options = new HashMap<>();
options.put("driver", MYSQL_DRIVER);
options.put("user", MYSQL_USERNAME);
options.put("password", MYSQL_PWD);
options.put("url", MYSQL_CONNECTION_URL);
options.put("dbtable", "(select emp_no, emp_id from employees) as employees_data");
options.put("lowerBound", "10001");
options.put("upperBound", "499999");
options.put("numPartitions", "10");
DataFrame jdbcDF = sqlContext.load("jdbc", options);
This gets an exception:
Exception in thread "main" java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended
I doubt that we can't give "as employees_data" for an Oracle query, so what am I doing wrong?