Showing posts with label create table. Show all posts
Showing posts with label create table. Show all posts

Wednesday, 1 April 2020

TableSaw: Create table from csv file

Below statement reads the data from 'sample.csv' file and create a table from it.
Table table = Table.read().csv("sample.csv");

employee.csv
1,Hari Krishna,Gurram
2,Kiran Kumar,Darsi
3,Rama Krishna,Gurram
4,Gopi,Battu
5,Sudheer,Ganji

App.java
package com.sample.app;

import java.io.IOException;

import tech.tablesaw.api.Table;

public class App {

 public static void main(String args[]) throws IOException {
  String csvFilePath = "/Users/krishna/Documents/employee.csv";

  Table table = Table.read().csv(csvFilePath);

  System.out.println(table.print());
 }
}

Output
          employee.csv           
 1  |  Hari Krishna  |  Gurram  |
---------------------------------
 2  |   Kiran Kumar  |   Darsi  |
 3  |  Rama Krishna  |  Gurram  |
 4  |          Gopi  |   Battu  |
 5  |       Sudheer  |   Ganji  |



Previous                                                    Next                                                    Home

Friday, 24 January 2020

Cassandra: IF NOT EXISTS: Create a table if it is not exist


‘IF NOT EXISTS’ keyword creates a table, if it is not exist, else ignore the execution.

Example
CREATE TABLE IF NOT EXISTS cassandratutorial.employee (
  id INT,
  firstName VARCHAR,
  PRIMARY KEY((id, firstName))
) WITH comment = 'Table to store Employee information';

Previous                                                    Next                                                    Home

Monday, 20 January 2020

Cassandra: Create a table


You can create a table using ‘CREATE TABLE’ command.

Syntax
CREATE TABLE [IF NOT EXISTS] [keyspace_name.]table_name ( 
   column_definition [, ...]
   PRIMARY KEY (column_name [, column_name ...])
[WITH table_options
   | CLUSTERING ORDER BY (clustering_column_name order])
   | ID = 'table_hash_tag'
   | COMPACT STORAGE]


Step 1: Create a keyspace ‘cassandratutorial’.
CREATE keyspace cassandratutorial WITH REPLICATION = 
{ 
 'class' : 'SimpleStrategy', 
 'replication_factor' : 3 
};


Step 2: Create a table employee like below.
CREATE TABLE cassandratutorial.employee (
  id INT, 
  firstName VARCHAR,
  PRIMARY KEY((id, firstName))
) WITH comment = 'Table to store Employee information';

You can get the information about a table using DESCRIBE command.

DESCRIBE cassandratutorial.employee;

cqlsh> CREATE keyspace cassandratutorial WITH REPLICATION = 
   ... { 
   ... 'class' : 'SimpleStrategy', 
   ... 'replication_factor' : 3 
   ... };
cqlsh> 
cqlsh> CREATE TABLE cassandratutorial.employee (
   ...   id INT, 
   ...   firstName VARCHAR,
   ...   PRIMARY KEY((id, firstName))
   ... ) WITH comment = 'Table to store Employee information';
cqlsh> 
cqlsh> DESCRIBE cassandratutorial.employee;

CREATE TABLE cassandratutorial.employee (
    id int,
    firstname text,
    PRIMARY KEY ((id, firstname))
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = 'Table to store Employee information'
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';



Previous                                                    Next                                                    Home