Support Questions

Find answers, ask questions, and share your expertise

not able to run hive query by putting it into .sql file

avatar
Contributor

I am able to run hive query through its shell but not able to run it by putting it into file. It gives me permission denied.

I tried to run it through hdfs user but still getting same error.

1 ACCEPTED SOLUTION

avatar
Master Guru

@Tajinderpal Singh

Below are the valid examples for running hive queries

  • Example of running a query from the command line
    $HIVE_HOME/bin/hive -e 'select a.col from tab1 a'
  • Example of setting Hive configuration variables
    $HIVE_HOME/bin/hive -e 'select a.col from tab1 a' --hiveconf hive.exec.scratchdir=/home/my/hive_scratch  --hiveconf mapred.reduce.tasks=32
  • Example of dumping data out from a query into a file using silent mode
    $HIVE_HOME/bin/hive -S -e 'select a.col from tab1 a' > a.txt
  • Example of running a script non-interactively from local disk
    $HIVE_HOME/bin/hive -f /home/my/hive-script.sql
  • Example of running a script non-interactively from a Hadoop supported filesystem (starting in Hive 0.14)
    $HIVE_HOME/bin/hive -f hdfs://<namenode>:<port>/hive-script.sql
    $HIVE_HOME/bin/hive -f s3://mys3bucket/s3-script.sql 
  • Example of running an initialization script before entering interactive mode
    $HIVE_HOME/bin/hive -i /home/my/hive-init.sql

View solution in original post

3 REPLIES 3

avatar
Super Guru

@Tajinderpal Singh

Please share the steps you performed along with error message.

avatar
Master Guru

@Tajinderpal Singh

Below are the valid examples for running hive queries

  • Example of running a query from the command line
    $HIVE_HOME/bin/hive -e 'select a.col from tab1 a'
  • Example of setting Hive configuration variables
    $HIVE_HOME/bin/hive -e 'select a.col from tab1 a' --hiveconf hive.exec.scratchdir=/home/my/hive_scratch  --hiveconf mapred.reduce.tasks=32
  • Example of dumping data out from a query into a file using silent mode
    $HIVE_HOME/bin/hive -S -e 'select a.col from tab1 a' > a.txt
  • Example of running a script non-interactively from local disk
    $HIVE_HOME/bin/hive -f /home/my/hive-script.sql
  • Example of running a script non-interactively from a Hadoop supported filesystem (starting in Hive 0.14)
    $HIVE_HOME/bin/hive -f hdfs://<namenode>:<port>/hive-script.sql
    $HIVE_HOME/bin/hive -f s3://mys3bucket/s3-script.sql 
  • Example of running an initialization script before entering interactive mode
    $HIVE_HOME/bin/hive -i /home/my/hive-init.sql

avatar
Contributor

Thanks kuldeep i am able to run hive queries by putting in file now.