Friday, 29 July 2022

SemanticException [Error 10293]: Unable to create temp file for insert values Expression of type TOK_FUNCTION not supported in insert/values

This error occurred when I tried to insert data into a Hive table that has some complex data.

 

After some analysis, I understood that, I need to use some temp table to insert data into a table with complex data.

 

Example

insert into employee select "1","Krishna",array('playing cricket', 'cooking');

 

Step 1: Create employee table.

CREATE TABLE employee (
    id INT,
    name STRING,
    hobbies ARRAY<STRING>
 )
 ROW FORMAT DELIMITED
 COLLECTION ITEMS TERMINATED BY ','
 STORED AS TEXTFILE;

 

hive> CREATE TABLE employee (
    >     id INT,
    >     name STRING,
    >     hobbies ARRAY<STRING>
    >  )
    >  ROW FORMAT DELIMITED
    >  COLLECTION ITEMS TERMINATED BY ','
    >  STORED AS TEXTFILE;
OK
Time taken: 0.109 seconds
hive> ;
hive> ;
hive> DESCRIBE employee;
OK
id                      int                                         
name                    string                                      
hobbies                 array<string>                               
Time taken: 0.038 seconds, Fetched: 3 row(s)

 

Step 2: Insert a record into employee table.

insert into employee select "1","Krishna",array('playing cricket', 'cooking');

 

hive> insert into employee select "1","Krishna",array('playing cricket', 'cooking');
Query ID = cloudera_20220418080808_136c810b-a426-4008-903b-aea5f5b46450
Total jobs = 3
Launching Job 1 out of 3
Number of reduce tasks is set to 0 since there's no reduce operator
Starting Job = job_1649172504056_0031, Tracking URL = http://quickstart.cloudera:8088/proxy/application_1649172504056_0031/
Kill Command = /usr/lib/hadoop/bin/hadoop job  -kill job_1649172504056_0031
Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 0
2022-04-18 08:08:11,564 Stage-1 map = 0%,  reduce = 0%
2022-04-18 08:08:19,268 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 1.76 sec
MapReduce Total cumulative CPU time: 1 seconds 760 msec
Ended Job = job_1649172504056_0031
Stage-4 is selected by condition resolver.
Stage-3 is filtered out by condition resolver.
Stage-5 is filtered out by condition resolver.
Moving data to: hdfs://quickstart.cloudera:8020/user/hive/warehouse/employee/.hive-staging_hive_2022-04-18_08-08-02_830_1093859265942969682-1/-ext-10000
Loading data to table default.employee
Table default.employee stats: [numFiles=1, numRows=1, totalSize=34, rawDataSize=33]
MapReduce Jobs Launched: 
Stage-Stage-1: Map: 1   Cumulative CPU: 1.76 sec   HDFS Read: 4186 HDFS Write: 106 SUCCESS
Total MapReduce CPU Time Spent: 1 seconds 760 msec
OK
Time taken: 17.742 seconds

 

Query employee table and confirm whether the data is inserted or not.

hive> SELECT * FROM employee;
OK
1   Krishna ["playing cricket","cooking"]
Time taken: 0.051 seconds, Fetched: 1 row(s)

 

 

Previous                                                    Next                                                    Home

How to get the version of tomcat installed in my system?

Tomcat provides version.sh script to get the tomcat version details.

 

Location of version.sh file

<TOMCAT_HOME>/bin

 

Navigate to tomcat bin directory and execute version.sh script to get tomcat version details.

$./version.sh 
Using CATALINA_BASE:   /Users/krishna/Documents/softwares/tomcat
Using CATALINA_HOME:   /Users/krishna/Documents/softwares/tomcat
Using CATALINA_TMPDIR: /Users/krishna/Documents/softwares/tomcat/temp
Using JRE_HOME:        /Library/Java/JavaVirtualMachines/jdk1.8.0_311.jdk/Contents/Home
Using CLASSPATH:       /Users/krishna/Documents/softwares/tomcat/bin/bootstrap.jar:/Users/krishna/Documents/softwares/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Server version: Apache Tomcat/10.0.23
Server built:   Jul 14 2022 08:16:11 UTC
Server number:  10.0.23.0
OS Name:        Mac OS X
OS Version:     10.16
Architecture:   x86_64
JVM Version:    1.8.0_311-b11
JVM Vendor:     Oracle Corporation

 


 

 

Previous                                                 Next                                                 Home

How to change tomcat port?

Apache tomcat runs on port 8080 by default.

 

How to customize the tomcat port?

By updating ‘<TOMCAT_HOME>/conf/server.xml’ file, we can customize the tomcat server port.

 

Open <TOMCAT_HOME>/conf/server.xml file in any editor, search for 8080, you will find below configuration.

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

 


Set the port number of your choice and save the changes. For example, I set the port number to 9090.

 

<Connector port="9090" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

Stop and start the tomcat server. Once the server started, open the url ‘http://localhost:9090/’ in browser, you will see tomcat home page.




Previous                                                 Next                                                 Home

How to deploy a war file to tomcat?

In this post, I am going to explain how to deploy a war file to Apache tomcat.

 

Prerequisite

Setup maven

Setup Java

 

This tutorial is devided into two sections.

a.   Create a war file

b.   Deploy the war file to tomcat.

 

Step 1: Create a war file.

 

Open terminal and execute below command to generate a sample Maven webapp project.

mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp -DarchetypeVersion=1.4

 

Above command generate the project in interactive mode. Provide below details.

a.   Version as 1

b.   Package as com.sample.app

c.    groupId as com.sample.app

d.   artifactId as helloworld

 

Upon successful completion of the above command, a webapp project template is created.

 

Project structure looks like below.

$tree helloworld/
|____
| |____pom.xml
| |____src
| | |____main
| | | |____webapp
| | | | |____index.jsp
| | | | |____WEB-INF
| | | | | |____web.xml

 

Navigate to the folder helloworld and execute the command ‘mvn clean install’ to generate a war file. Generated war file location is helloworld/target/helloworld.war.

 

Step 2: Deploy the war file to tomcat. You can find the instructions to setup tomcat here.

 

Start the tomcat server. Open the url ‘http://localhost:8080/’ in browser.

 


Click on Manager App button. It prompts you for the login details.

 

 


Enter username and password that you configured, click on Sign In button. You will be taken to ‘Tomcat Web Application Manager’ page.

 

Navigate to 'WAR file to deploy' section in Tomcat Web Application Manager page.




Browse the war file, and click on Deploy button.

 

Once deployment is successful, you can see helloworld application is available in Applications section.

 


 

Click on the hyperlink helloworld, to open the helloworld application.

 


 

That’s it, you are done…


  

Previous                                                 Next                                                 Home

What is the tomcat default admin password?

By default there is no user configured with tomcat setup.

 

How to add a tomcat user?

Open the file ‘{TOMCAT_INSTALL_DIR}/conf/tomcat-users.xml’

 

Add below statements between <tomcat-users> </tomcat-users> element.

 

<role rolename="manager-gui"/>

<user username="admin" password="admin" roles="manager-gui"/>

 

Start the tomcat server again, open the url ‘http://localhost:8080’ in browser. Click on ‘Manager App’ button, it prompts you for the login details.

 


Enter username as admin and password as admin, click on Sign In button. You will be taken to ‘Tomcat Web Application Manager’ page.



Previous                                                 Next                                                 Home

Setup Apache tomcat in Mac

In this post, I am going to explain how to setup Apache tomcat, and configure users to work with tomcat web user interface.

 

Prerequisite

Make sure Java is installed in your system.

 

Step 1: Go to below location and download Apache tomcat latest release.

https://tomcat.apache.org/

 

At the time of writing this post 10.0.23 is the latest version.

 

Step 2: Create tomcat folder and extract the downloaded zip file contents to tomcat folder.

 


 

Step 3: We need to give execute permission to the scripts available in bin folder. Open terminal, navigate to the bin folder and execute below command to give execute permissions to all the .sh files.

chmod +x *sh

You can confirm the same by executing ‘ls -lart’ command.

$ ls -lart *sh
-rw-r--r--@ 1 krishna  staff   1908 Jul 14 10:16 version.sh
-rw-r--r--@ 1 krishna  staff   5540 Jul 14 10:16 tool-wrapper.sh
-rw-r--r--@ 1 krishna  staff   1904 Jul 14 10:16 startup.sh
-rw-r--r--@ 1 krishna  staff   1902 Jul 14 10:16 shutdown.sh
-rw-r--r--@ 1 krishna  staff   3708 Jul 14 10:16 setclasspath.sh
-rw-r--r--@ 1 krishna  staff   1970 Jul 14 10:16 migrate.sh
-rw-r--r--@ 1 krishna  staff   3382 Jul 14 10:16 makebase.sh
-rw-r--r--@ 1 krishna  staff   1965 Jul 14 10:16 digest.sh
-rw-r--r--@ 1 krishna  staff   8836 Jul 14 10:16 daemon.sh
-rw-r--r--@ 1 krishna  staff   1922 Jul 14 10:16 configtest.sh
-rw-r--r--@ 1 krishna  staff   1997 Jul 14 10:16 ciphers.sh
-rw-r--r--@ 1 krishna  staff  24814 Jul 14 10:16 catalina.sh
$
$
$ chmod +x *sh
$ 
$ ls -lart *sh
-rwxr-xr-x@ 1 krishna  staff   1908 Jul 14 10:16 version.sh
-rwxr-xr-x@ 1 krishna  staff   5540 Jul 14 10:16 tool-wrapper.sh
-rwxr-xr-x@ 1 krishna  staff   1904 Jul 14 10:16 startup.sh
-rwxr-xr-x@ 1 krishna  staff   1902 Jul 14 10:16 shutdown.sh
-rwxr-xr-x@ 1 krishna  staff   3708 Jul 14 10:16 setclasspath.sh
-rwxr-xr-x@ 1 krishna  staff   1970 Jul 14 10:16 migrate.sh
-rwxr-xr-x@ 1 krishna  staff   3382 Jul 14 10:16 makebase.sh
-rwxr-xr-x@ 1 krishna  staff   1965 Jul 14 10:16 digest.sh
-rwxr-xr-x@ 1 krishna  staff   8836 Jul 14 10:16 daemon.sh
-rwxr-xr-x@ 1 krishna  staff   1922 Jul 14 10:16 configtest.sh
-rwxr-xr-x@ 1 krishna  staff   1997 Jul 14 10:16 ciphers.sh
-rwxr-xr-x@ 1 krishna  staff  24814 Jul 14 10:16 catalina.sh

From the above snippet, you can notice that prior to the execution of chmod command, *.sh files do not have execute permission, after that x flag is added to all the *sh files.

 

Step 4: Execute the file ./startup.sh

bash-3.2$ ./startup.sh 
Using CATALINA_BASE:   /Users/krishna/Documents/softwares/tomcat
Using CATALINA_HOME:   /Users/krishna/Documents/softwares/tomcat
Using CATALINA_TMPDIR: /Users/krishna/Documents/softwares/tomcat/temp
Using JRE_HOME:        /Library/Java/JavaVirtualMachines/jdk-15.0.2.jdk/Contents/Home
Using CLASSPATH:       /Users/krishna/Documents/softwares/tomcat/bin/bootstrap.jar:/Users/krishna/Documents/softwares/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Tomcat started.


Let’s confirm the same by opening the url ‘http://localhost:8080/’ in browser.




That’s it you are done with the setup…

 

How to stop the tomcat server?

Execute the command ‘./shutdown.sh’.

 

$./shutdown.sh 
Using CATALINA_BASE:   /Users/krishna/Documents/softwares/tomcat
Using CATALINA_HOME:   /Users/krishna/Documents/softwares/tomcat
Using CATALINA_TMPDIR: /Users/krishna/Documents/softwares/tomcat/temp
Using JRE_HOME:        /Library/Java/JavaVirtualMachines/jdk-15.0.2.jdk/Contents/Home
Using CLASSPATH:       /Users/krishna/Documents/softwares/tomcat/bin/bootstrap.jar:/Users/krishna/Documents/softwares/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
NOTE: Picked up JDK_JAVA_OPTIONS:  --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED

 

Another way to start and stop the tomcat

./catalina.sh start: Start the tomcat server.

$./catalina.sh start
Using CATALINA_BASE:   /Users/krishna/Documents/softwares/tomcat
Using CATALINA_HOME:   /Users/krishna/Documents/softwares/tomcat
Using CATALINA_TMPDIR: /Users/krishna/Documents/softwares/tomcat/temp
Using JRE_HOME:        /Library/Java/JavaVirtualMachines/jdk-15.0.2.jdk/Contents/Home
Using CLASSPATH:       /Users/krishna/Documents/softwares/tomcat/bin/bootstrap.jar:/Users/krishna/Documents/softwares/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Tomcat started.

 

./catalina.sh stop: Stop the tomcat server.

$./catalina.sh stop
Using CATALINA_BASE:   /Users/krishna/Documents/softwares/tomcat
Using CATALINA_HOME:   /Users/krishna/Documents/softwares/tomcat
Using CATALINA_TMPDIR: /Users/krishna/Documents/softwares/tomcat/temp
Using JRE_HOME:        /Library/Java/JavaVirtualMachines/jdk-15.0.2.jdk/Contents/Home
Using CLASSPATH:       /Users/krishna/Documents/softwares/tomcat/bin/bootstrap.jar:/Users/krishna/Documents/softwares/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
NOTE: Picked up JDK_JAVA_OPTIONS:  --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
$

 

Configure tomcat users

By default there is no user configured with tomcat setup.

 

How to add a tomcat user?

Open the file ‘{TOMCAT_INSTALL_DIR}/conf/tomcat-users.xml’

 

Add below statements between <tomcat-users> </tomcat-users> element.

<role rolename="manager-gui"/>
<user username="admin" password="admin" roles="manager-gui"/>

  Start the tomcat server again, open the url ‘http://localhost:8080’ in browser. Click on ‘Manager App’ button, it prompts you for the login details.

 


Enter username as admin and password as admin, click on Sign In button. You will be taken to ‘Tomcat Web Application Manager’ page.



 

 


Previous                                                 Next                                                 Home