Skip to content

Instantly share code, notes, and snippets.

View corneliouzbett's full-sized avatar
:octocat:
Compiling dreams and ideas...

Kipchumba Bett corneliouzbett

:octocat:
Compiling dreams and ideas...
View GitHub Profile
public final class TodoListContract {
private TodoListContract() {}
public static class TodoListEntries implements BaseColumns {
public static final String TABLE_NAME = "TodolistEntries";
public static final String COLUMN_NAME_CONTENT = "content";
public static final String COLUMN_NAME_DONE = "done";
public static final String COLUMN_NAME_REMINDERDATE = "reminderdate";
}
}
def test_fit_minimize_metric(self):
sqlContext = SQLContext(self.sc)
dataset = sqlContext.createDataFrame([
(10, 10.0),
(50, 50.0),
(100, 100.0),
(500, 500.0)] * 10,
["feature", "label"])
iee = InducedErrorEstimator()
def main():
spark = SparkSession \
.builder \
.appName("RandomForest") \
.config("spark.executor.heartbeatInterval","60s")\
.getOrCreate()
sc = spark.sparkContext
sqlContext = SQLContext(sc)
vote down vote up
def test_fit_maximize_metric(self):
sqlContext = SQLContext(self.sc)
dataset = sqlContext.createDataFrame([
(10, 10.0),
(50, 50.0),
(100, 100.0),
(500, 500.0)] * 10,
["feature", "label"])
def generate_code(self):
code = dedent(u"""
from pyspark.sql import SQLContext
# Input data
sql_context = SQLContext(spark_session.sparkContext)
if {in1} is not None:
sql_context.registerDataFrameAsTable({in1}, 'ds1')
if {in2} is not None:
sql_context.registerDataFrameAsTable({in2}, 'ds2')
@corneliouzbett
corneliouzbett / dtschema.py
Created March 20, 2019 08:43
create a empty dataframe from schema
from pyspark.sql.types import *
field = [StructField(“FIELDNAME_1”,StringType(), True),StructField(“FIELDNAME_2”, StringType(), True),\
StructField(“FIELDNAME_3”, StringType(), True)]
schema = StructType(field)
df = sqlContext.createDataFrame(sc.emptyRDD(), schema)
// Create the dataframe
val df = Seq("Red", "Green", "Blue").map(Tuple1.apply).toDF("color")
df.createOrReplaceTempView("data")
val df4 = sql(""" select *, case when color = 'green' then 1 else 0 end as Green_ind from data """)
df4.show()
df4:org.apache.spark.sql.DataFrame = [color: string, Green_ind: integer]
@corneliouzbett
corneliouzbett / sparkcase.sbt
Created March 19, 2019 11:59
Apache spark case when else in sql
val df = spark.createDataFrame(Seq(( 2, 9), ( 1, 5),( 1, 1),( 1, 2),( 2, 8))) .toDF("y", "x")
df.createOrReplaceTempView("test")
spark.sql("select CASE WHEN y = 2 THEN 'A' ELSE 'B' END AS flag, x from test").show
df:org.apache.spark.sql.DataFrame = [y: integer, x: integer]
# Start running the query that prints the running counts to the console
query = wordCounts \
.writeStream \
.outputMode("complete") \
.format("console") \
.start()
query.awaitTermination()
@corneliouzbett
corneliouzbett / SQL_read.py
Created March 18, 2019 13:48
python reading from mysql database datasource
from pyspark.sql import SQLContext
from pyspark import SparkContext, SparkConf
import os
SUBMIT_ARGS = "--packages mysql:mysql-connector-java:5.1.39 pyspark-shell"
os.environ["PYSPARK_SUBMIT_ARGS"] = SUBMIT_ARGS
conf = SparkConf().setAppName("Flat obs Data flow")\
.setMaster("local[*]")