Couldn't execute hive current_user function from spark sql












0















I am trying to execute hive SQL from spark. The following works fine using spark-sql or from spark-submit for python with embedded hive sql statements.



spark-sql --master yarn -e "select count(*) from adhoc.dual;"


But I can't execute
spark-sql --master yarn -e "select current_user() from adhoc.dual;"



I get the following error



Error in query: Undefined function: 'current_user'. This function is neither a registered temporary function nor a permanent function registered in the database 'default'.; line 1 pos 7


current_user is a hive permanent function.



Similarly from pyspark, I can execute most of hive statements including the ones involving user defined UDF after register the UDF as temporary function like:
CREATE TEMPORARY FUNCTION foo AS 'com.example.foo';



But execution of hive's create macro results in failure



from pyspark.sql import SparkSession
from pyspark.sql import Row
from pyspark.sql.types import IntegerType, StringType
import pyspark.sql.functions as F

spark = SparkSession.builder.appName("Python Spark Hive example").enableHiveSupport().getOrCreate()
spark.sql("CREATE TEMPORARY MACRO PacificTzDate(ts BIGINT) DATE(FROM_UTC_TIMESTAMP(FROM_UNIXTIME(ts, 'yyyy-MM-dd HH:mm:ss'), 'America/Los_Angeles')")


This fails with the following error:



pyspark.sql.utils.ParseException: u"nOperation not allowed: CREATE TEMPORARY MACRO(line 1, pos 0)nn== SQL ==nCREATE TEMPORARY MACRO PacificTzDate(ts BIGINT) DATE(FROM_UTC_TIMESTAMP(FROM_UNIXTIME(ts, 'yyyy-MM-dd HH:mm:ss'), 'America/Los_Angeles')n^^^n"


19/01/02 20:09:49 INFO SparkContext: Invoking stop() from shutdown hook










share|improve this question























  • Could you try replacing with hive -e "select col, 'whoami' from table1; or logged_in_user()

    – Antonio Cachuan
    Jan 2 at 20:42











  • Did you mean running the SQL from hive? hive2_3 --version Hive 2.3.4-SNAPSHOT hive2_3 -e "select current_user()" Logging initialized using configuration in file:/mnt/apache-hive-2.3.4-SNAPSHOT-bin/conf/hive-log4j2.properties Async: true OK _c0 XYZ Time taken: 0.608 seconds, Fetched: 1 row(s) hive2_3 -e "select logged_in_user()" Logging initialized using configuration in file:/mnt/apache-hive-2.3.4-SNAPSHOT-bin/conf/hive-log4j2.properties Async: true OK _c0 NULL Time taken: 0.486 seconds, Fetched: 1 row(s)

    – user3138594
    Jan 2 at 21:40


















0















I am trying to execute hive SQL from spark. The following works fine using spark-sql or from spark-submit for python with embedded hive sql statements.



spark-sql --master yarn -e "select count(*) from adhoc.dual;"


But I can't execute
spark-sql --master yarn -e "select current_user() from adhoc.dual;"



I get the following error



Error in query: Undefined function: 'current_user'. This function is neither a registered temporary function nor a permanent function registered in the database 'default'.; line 1 pos 7


current_user is a hive permanent function.



Similarly from pyspark, I can execute most of hive statements including the ones involving user defined UDF after register the UDF as temporary function like:
CREATE TEMPORARY FUNCTION foo AS 'com.example.foo';



But execution of hive's create macro results in failure



from pyspark.sql import SparkSession
from pyspark.sql import Row
from pyspark.sql.types import IntegerType, StringType
import pyspark.sql.functions as F

spark = SparkSession.builder.appName("Python Spark Hive example").enableHiveSupport().getOrCreate()
spark.sql("CREATE TEMPORARY MACRO PacificTzDate(ts BIGINT) DATE(FROM_UTC_TIMESTAMP(FROM_UNIXTIME(ts, 'yyyy-MM-dd HH:mm:ss'), 'America/Los_Angeles')")


This fails with the following error:



pyspark.sql.utils.ParseException: u"nOperation not allowed: CREATE TEMPORARY MACRO(line 1, pos 0)nn== SQL ==nCREATE TEMPORARY MACRO PacificTzDate(ts BIGINT) DATE(FROM_UTC_TIMESTAMP(FROM_UNIXTIME(ts, 'yyyy-MM-dd HH:mm:ss'), 'America/Los_Angeles')n^^^n"


19/01/02 20:09:49 INFO SparkContext: Invoking stop() from shutdown hook










share|improve this question























  • Could you try replacing with hive -e "select col, 'whoami' from table1; or logged_in_user()

    – Antonio Cachuan
    Jan 2 at 20:42











  • Did you mean running the SQL from hive? hive2_3 --version Hive 2.3.4-SNAPSHOT hive2_3 -e "select current_user()" Logging initialized using configuration in file:/mnt/apache-hive-2.3.4-SNAPSHOT-bin/conf/hive-log4j2.properties Async: true OK _c0 XYZ Time taken: 0.608 seconds, Fetched: 1 row(s) hive2_3 -e "select logged_in_user()" Logging initialized using configuration in file:/mnt/apache-hive-2.3.4-SNAPSHOT-bin/conf/hive-log4j2.properties Async: true OK _c0 NULL Time taken: 0.486 seconds, Fetched: 1 row(s)

    – user3138594
    Jan 2 at 21:40
















0












0








0








I am trying to execute hive SQL from spark. The following works fine using spark-sql or from spark-submit for python with embedded hive sql statements.



spark-sql --master yarn -e "select count(*) from adhoc.dual;"


But I can't execute
spark-sql --master yarn -e "select current_user() from adhoc.dual;"



I get the following error



Error in query: Undefined function: 'current_user'. This function is neither a registered temporary function nor a permanent function registered in the database 'default'.; line 1 pos 7


current_user is a hive permanent function.



Similarly from pyspark, I can execute most of hive statements including the ones involving user defined UDF after register the UDF as temporary function like:
CREATE TEMPORARY FUNCTION foo AS 'com.example.foo';



But execution of hive's create macro results in failure



from pyspark.sql import SparkSession
from pyspark.sql import Row
from pyspark.sql.types import IntegerType, StringType
import pyspark.sql.functions as F

spark = SparkSession.builder.appName("Python Spark Hive example").enableHiveSupport().getOrCreate()
spark.sql("CREATE TEMPORARY MACRO PacificTzDate(ts BIGINT) DATE(FROM_UTC_TIMESTAMP(FROM_UNIXTIME(ts, 'yyyy-MM-dd HH:mm:ss'), 'America/Los_Angeles')")


This fails with the following error:



pyspark.sql.utils.ParseException: u"nOperation not allowed: CREATE TEMPORARY MACRO(line 1, pos 0)nn== SQL ==nCREATE TEMPORARY MACRO PacificTzDate(ts BIGINT) DATE(FROM_UTC_TIMESTAMP(FROM_UNIXTIME(ts, 'yyyy-MM-dd HH:mm:ss'), 'America/Los_Angeles')n^^^n"


19/01/02 20:09:49 INFO SparkContext: Invoking stop() from shutdown hook










share|improve this question














I am trying to execute hive SQL from spark. The following works fine using spark-sql or from spark-submit for python with embedded hive sql statements.



spark-sql --master yarn -e "select count(*) from adhoc.dual;"


But I can't execute
spark-sql --master yarn -e "select current_user() from adhoc.dual;"



I get the following error



Error in query: Undefined function: 'current_user'. This function is neither a registered temporary function nor a permanent function registered in the database 'default'.; line 1 pos 7


current_user is a hive permanent function.



Similarly from pyspark, I can execute most of hive statements including the ones involving user defined UDF after register the UDF as temporary function like:
CREATE TEMPORARY FUNCTION foo AS 'com.example.foo';



But execution of hive's create macro results in failure



from pyspark.sql import SparkSession
from pyspark.sql import Row
from pyspark.sql.types import IntegerType, StringType
import pyspark.sql.functions as F

spark = SparkSession.builder.appName("Python Spark Hive example").enableHiveSupport().getOrCreate()
spark.sql("CREATE TEMPORARY MACRO PacificTzDate(ts BIGINT) DATE(FROM_UTC_TIMESTAMP(FROM_UNIXTIME(ts, 'yyyy-MM-dd HH:mm:ss'), 'America/Los_Angeles')")


This fails with the following error:



pyspark.sql.utils.ParseException: u"nOperation not allowed: CREATE TEMPORARY MACRO(line 1, pos 0)nn== SQL ==nCREATE TEMPORARY MACRO PacificTzDate(ts BIGINT) DATE(FROM_UTC_TIMESTAMP(FROM_UNIXTIME(ts, 'yyyy-MM-dd HH:mm:ss'), 'America/Los_Angeles')n^^^n"


19/01/02 20:09:49 INFO SparkContext: Invoking stop() from shutdown hook







apache-spark pyspark hiveql






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 2 at 20:14









user3138594user3138594

3515




3515













  • Could you try replacing with hive -e "select col, 'whoami' from table1; or logged_in_user()

    – Antonio Cachuan
    Jan 2 at 20:42











  • Did you mean running the SQL from hive? hive2_3 --version Hive 2.3.4-SNAPSHOT hive2_3 -e "select current_user()" Logging initialized using configuration in file:/mnt/apache-hive-2.3.4-SNAPSHOT-bin/conf/hive-log4j2.properties Async: true OK _c0 XYZ Time taken: 0.608 seconds, Fetched: 1 row(s) hive2_3 -e "select logged_in_user()" Logging initialized using configuration in file:/mnt/apache-hive-2.3.4-SNAPSHOT-bin/conf/hive-log4j2.properties Async: true OK _c0 NULL Time taken: 0.486 seconds, Fetched: 1 row(s)

    – user3138594
    Jan 2 at 21:40





















  • Could you try replacing with hive -e "select col, 'whoami' from table1; or logged_in_user()

    – Antonio Cachuan
    Jan 2 at 20:42











  • Did you mean running the SQL from hive? hive2_3 --version Hive 2.3.4-SNAPSHOT hive2_3 -e "select current_user()" Logging initialized using configuration in file:/mnt/apache-hive-2.3.4-SNAPSHOT-bin/conf/hive-log4j2.properties Async: true OK _c0 XYZ Time taken: 0.608 seconds, Fetched: 1 row(s) hive2_3 -e "select logged_in_user()" Logging initialized using configuration in file:/mnt/apache-hive-2.3.4-SNAPSHOT-bin/conf/hive-log4j2.properties Async: true OK _c0 NULL Time taken: 0.486 seconds, Fetched: 1 row(s)

    – user3138594
    Jan 2 at 21:40



















Could you try replacing with hive -e "select col, 'whoami' from table1; or logged_in_user()

– Antonio Cachuan
Jan 2 at 20:42





Could you try replacing with hive -e "select col, 'whoami' from table1; or logged_in_user()

– Antonio Cachuan
Jan 2 at 20:42













Did you mean running the SQL from hive? hive2_3 --version Hive 2.3.4-SNAPSHOT hive2_3 -e "select current_user()" Logging initialized using configuration in file:/mnt/apache-hive-2.3.4-SNAPSHOT-bin/conf/hive-log4j2.properties Async: true OK _c0 XYZ Time taken: 0.608 seconds, Fetched: 1 row(s) hive2_3 -e "select logged_in_user()" Logging initialized using configuration in file:/mnt/apache-hive-2.3.4-SNAPSHOT-bin/conf/hive-log4j2.properties Async: true OK _c0 NULL Time taken: 0.486 seconds, Fetched: 1 row(s)

– user3138594
Jan 2 at 21:40







Did you mean running the SQL from hive? hive2_3 --version Hive 2.3.4-SNAPSHOT hive2_3 -e "select current_user()" Logging initialized using configuration in file:/mnt/apache-hive-2.3.4-SNAPSHOT-bin/conf/hive-log4j2.properties Async: true OK _c0 XYZ Time taken: 0.608 seconds, Fetched: 1 row(s) hive2_3 -e "select logged_in_user()" Logging initialized using configuration in file:/mnt/apache-hive-2.3.4-SNAPSHOT-bin/conf/hive-log4j2.properties Async: true OK _c0 NULL Time taken: 0.486 seconds, Fetched: 1 row(s)

– user3138594
Jan 2 at 21:40














0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54012584%2fcouldnt-execute-hive-current-user-function-from-spark-sql%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54012584%2fcouldnt-execute-hive-current-user-function-from-spark-sql%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

Npm cannot find a required file even through it is in the searched directory