Categories
hive

How to create external table in hive

In this post let us learn how to create external table in hive

Types of table in hive

The following are the two types of tables in the hive.

  1. Internal table or Managed table
  2. External table

For getting familiar with internal tables, Please refer to the below link.

https://beginnersbug.com/how-to-create-a-table-in-hive/  

What is External table ?

For creating an external table, we need to use one keyword called external.

The remaining syntax will remain the same for both types.

How to create ?

Following is the syntax for creating an external table.

Fields terminated by  ‘,’ – need to specify the delimiter of the file to be loaded into the table.

hive> create external table temp_details (year string,temp int,place string) 
> row format delimited 
> fields terminated by ','; 
OK Time taken: 0.093 seconds

To get familiar with loading the table, Please refer to the following link.

https://beginnersbug.com/how-to-load-data-into-a-hive-table/

Categories
file java

create text file from java with example

In this post, we are going to learn create text file from java with example

In this example, we are going to use File.java to create file

please make sure your code is under try catch block. Because there is chance to getting IOException

Prerequisites
  • Java installed
  • your program should have access to create file on the path
Syntax
	file.createNewFile();
Example
import java.io.File;

public class CreateFileExample {

	public static void main(String[] args) {
		try {
			File file = new File("C://temp//sample.txt");
			// .exists Method check if file already exists on the path
			if (!file.exists()) {
				// Below line will create file sample.txt on C://temp// folder
				file.createNewFile();
				System.out.println("File created succesfully !!");
			} else {

				System.err.println("File already exists");
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
Output
File created succesfully !!

if file already exists in the C://temp folder we will get below output

File already exists
Access denied

Make sure you have access from java to create file on the folder else you will get access denied exception like below

java.io.IOException: Access is denied
	at java.io.WinNTFileSystem.createFileExclusively(Native Method)
	at java.io.File.createNewFile(File.java:1012)
	at com.geeks.example.CreateFileEaxmple.main(CreateFileEaxmple.java:11)
Github

https://github.com/rkumar9090/BeginnersBug/blob/master/BegineersBug/src/com/geeks/example/files/CreateFileExample.java

Related Articles

how to read a file from java with example