Skip to content

Instantly share code, notes, and snippets.

View robcowie's full-sized avatar

Rob Cowie robcowie

  • Recycleye
  • Leeds/London, United Kingdom
View GitHub Profile
@robcowie
robcowie / date_range_n_days.py
Last active March 2, 2020 10:44
Generate date range from start date for N days
import datetime as dt
import operator as op
def date_iterator(from_date, days, reverse=False):
func = op.sub if reverse else op.add
return (func(from_date, dt.timedelta(days=d)) for d in range(days))
def date_range(from_date, to_date, inclusive=True):
@robcowie
robcowie / hdfs-ha-namenode-failback.sh
Created October 15, 2017 20:22 — forked from salekseev/hdfs-ha-namenode-failback.sh
Script to check that both NameNodes are alive in HDFS HA configuration and will force failover to the preferred NameNode
#!/bin/bash
#
# This script will check that both NameNodes are alive in HDFS HA
# configuration and will force failover to the preferred NameNode.
#
# Author: Stas Alekseev <me@salekseev.com>
#
ACTIVE_NAMENODE=nn1
STANDBY_NAMENODE=nn2
@robcowie
robcowie / distcp_examples.sh
Created June 20, 2017 19:10
distcp Examples
# export HADOOP_OPTS=-Xmx28G
export HADOOP_CLIENT_OPTS="-Xmx2048m"
hadoop distcp -p "hdfs://plat/data/level1/clicks/datehour=2016-12-*" "gs://data-events/data/level1/clicks/"
@robcowie
robcowie / delete_table_from_metastore.sql
Last active July 17, 2025 13:50
Drop a table form the hive metastore
# DELETE A TABLE IN THE HIVE METASTORE
# BE CAREFUL! BACKUP THE DB BEFORE PROCEEDING!
set @table_name = '';
SELECT @tbl_id := TBl_ID FROM TBLS WHERE TBL_NAME = @table_name;
-- Delete partition key vals
DELETE pvk
FROM PARTITION_KEY_VALS pvk
@robcowie
robcowie / hdfs_usage_notes.md
Last active February 12, 2017 14:59
HDFS Usage Notes

HDFS Notes

Moving files to and from HDFS

hdfs dfs -copyFromLocal file hdfs://path/to/dir/file
hdfs dfs -copyToLocal hdfs://path/to/dir/file file

Moving files within the cluster

@robcowie
robcowie / ip_to_numeric.py
Last active February 28, 2017 22:13
IP to Numeric with obfuscation
example1 = 1118363648
def numeric_to_ip(ip):
parts = []
while ip:
parts.append(ip & 255)
ip = ip >> 8
return '.'.join([str(p) for p in reversed(parts)])
@robcowie
robcowie / notes_oozie.md
Created January 15, 2017 12:29
Oozie notes & links
import logging
import time
logger = logging.getLogger(__name__)
class NoSuchActivityError(Exception):
pass
@robcowie
robcowie / spark_s3_fs_notes.md
Created June 13, 2016 08:41
Configure S3 filesystem support for Spark on OSX

Configure S3 filesystem support for Spark on OSX

Homebrew installed Spark 1.6.x

  1. Install hadoop to get the required jars (brew install hadoop)
  2. Create a spark-env.sh (cp /usr/local/Cellar/apache-spark/1.6.1/libexec/conf/spark-env.sh.template /usr/local/Cellar/apache-spark/1.6.1/libexec/conf/spark-env.sh)
  3. Set HADOOP_CONF_DIR in spark-env.sh (export HADOOP_CONF_DIR=/usr/local/Cellar/hadoop/2.7.2/libexec/etc/hadoop/)
  4. Add the required jars to the SPARK_CLASSPATH in spark-env.sh
@robcowie
robcowie / emr_notes.md
Last active March 17, 2016 12:09
EMR & EC2 Notes

EMR

Submit an S3DistCP step using awscli

# AMI 3.x
aws emr add-steps\
  --cluster-id j-xxxxxxxxxxx\
  --steps 'Type=CUSTOM_JAR,Name="s3distcpstep",Jar=/home/hadoop/lib/emr-s3distcp-1.0.jar,Args=["--src=s3://","--dest=s3://"]'