Vous êtes sur la page 1sur 4

COMANDOS HDFS

COMANDO FUNCIÓN
pwd Ver directorio actual
:wq Para salir y guardar un archivo
../ Para copiar y mover un archivo (igual que en HTML)
hdfs dfs Usar hdfs
mkdir -p CarpetaGeneral/{carpeta1,carpeta2,carpeta3,carpeta4} Múltiples carpetas
hdfs dfs -rm -r /directorio Eliminar directorios
hdfs dfs -put /directorio local/proyecto.txt /directorio ddfs/proyecto.txt Subir archivos al dfs/nube
hdfs dfs -ls /ruta Ver carpetas y archivos para evitar moverte
hdfs dfs -cp Copiar en hdfs se usa con guion
hdfs dfs -chmod 777 Otorgar todos los permisos
hdfs dfs -ls /user/hive/warehouse Ruta donde se guardan tablas internas

COMANDOS HIVE

COMANDO FUNCIÓN

select *from proyecto; Ver datos


set hive.exec.dynamic.partition.mode=nonstrict;
Se requiere ejecutarlo en hive para ingestar
set hive.exec.dynamic.partition=true;
show create table int_empleados; Ver como se creo una tabla
ALTER TABLE nombreTabla RENAME TO nombreTablaNuevo; Cambia el nombre de la tabla de nombreTabla a nombreTablaNuevo
CREACIÓN DE TABLAS EXTERNAS

CREATE EXTERNAL TABLE IF NOT EXISTS


crgarciat.ext_prueba(
id string,
Nombre string,
Apellido string,
FechaNacimiento string,
Universidad string,
CodigoTitulacion string
)
ROW FORMAT delimited fields terminated by '|' lines terminated by '\n'
STORED AS textfile
LOCATION
'/user/crgarciat/tribu/carpeta'
tblproperties("skip.header.line.count" = "1");

CREACIÓN DE TABLAS EXTERNAS CON SEPARACIÓN POR ESPACIOS

CREATE EXTERNAL TABLE IF NOT EXISTS


proyecto(
ID_PROYECTO string,
PROYECTO string,
FCH_INICIO string,
FCH_TERMINO string
)
ROW FORMAT SERDE 'org.apache.hadoop.hive.contrib.serde2.RegexSerDe'
WITH SERDEPROPERTIES("input.regex" = "(.{1})(.{12})(.{10})(.{10})")
STORED AS textfile
LOCATION '/user/crgarciat/tribu/carpetaBase/proyecto'
tblproperties("skip.header.line.count" = "1");

CREACIÓN DE TABLAS PARTICIONADAS


CREATE TABLE IF NOT EXISTS int_empleados
(id_empleado int,
nombre string,
apellido string,
fecha_nacimiento DATE,
id_puesto int,
id_tienda int,
salario float,
fecha_ingreso DATE,
sexo string,
nombre_archivo string,
fecha_ingesta DATE)
partitioned by (estado string)
STORED AS ORC;

CREACIÓN DE TABLAS INTERNAS

CREATE TABLE IF NOT EXISTS interna_proyecto(


ID_PROYECTO int,
PROYECTO string,
FCH_INICIO DATE,
FCH_TERMINO DATE
)
STORED AS ORC;

MANDAR DATOS A UNA TABLA

insert overwrite table int_empleados partition(estado)


select cast(id_empleado as int),
nombre,
apellidos,
from_unixtime(unix_timestamp(fch_nac,'dd/MM/yyyy'), 'yyyy-MM-dd'),
cast(id_puesto as int),
cast(id_tienda as int),
cast(salario as float),
from_unixtime(unix_timestamp(fch_ingreso,'dd/MM/yyyy'), 'yyyy-MM-dd'),
sexo,
input__file__name,
current_date,
estado
from empleado;

insert into table int_empleados partition(campo4)


select cast(campo1 as int),
Cast(campo2 as float),
from_unixtime(unix_timestamp(fecha_campo3,'dd/MM/yyyy'), 'yyyy-MM-dd'),
Campo4

from tabla_origen;

Vous aimerez peut-être aussi