SlideShare a Scribd company logo
Storing Sensor data using User Defined Types
Andy Cobley
• Senior lecturer, (Professor), University of Dundee
• Program Director of MSc programs in
– Data Science (http://www.dundee.ac.uk/study/pg/data-science/ )
– Data Engineering (http://www.dundee.ac.uk/study/pg/data-engineering/ )
2© 2015. All Rights Reserved.
1 Sensors, Our problem
2 User defined types
3 With collections
4 Reading and Writing Sensor data
3© 2015. All Rights Reserved.
Sensors
• We were interested in sampling soil moisture (and other values)
• At scale
• Potentially allows us to calibrate satellites.
– Sentinel-1, SMAP
• Many existing data sets are very old, especially in developing
countries
4© 2015. All Rights Reserved.
http://www.ukeof.org.uk/documents/dagsoiltestingkit.pdf
Sensors
• Soil sensors can be very expensive
– Data Loggers can be $100’s
• Can have problems with trailing wires
– Data muling can overcome that.
• We want lots of people to take part (20,000)
5© 2015. All Rights Reserved.
Sensors
• So:
– Lets let people make their own
– Raspberry pi and AirPi
– Smart Citizen
– MudPi
6© 2015. All Rights Reserved.
Open Source
• Each device sends different data
• Airpi:
– Temperature, humidity, air pressure, light levels, UV levels, carbon
monoxide, nitrogen dioxide and smoke level
• Smart Citizen
– Carbon Monoxide (CO), Nitrogen Oxide (NO2),
Temperature,Humidity,LightSound
7© 2015. All Rights Reserved.
Open Source
• Each has it’s own source code, data can be sent in different
data types
– Int, Float, String ?
• So we don’t know what each sensor will send or what type it will
be.
• This was experimental, a kind of what if ?
8© 2015. All Rights Reserved.
Relational solutions
• We can create relational tables, but we are likely to end up
dealing with a lot of nulls.
• Decisions we make might go out of date (sensors that send
much more data than expected)
• You can probably find a relational solution, but it won’t be pretty!
9© 2015. All Rights Reserved.
Lets use User Defined Types
• Why ?
– Allow us to ignore the nulls
© 2015. All Rights Reserved. 10
User Defined Types
11© 2015. All Rights Reserved.
CREATE TYPE if not exists SensorReading (
fValue float,
sValue text,
iValue int,
Accuracy float
);
If we have one sensor reading
12© 2015. All Rights Reserved.
Create table if not exists untypedSensor(
name uuid,
insertion_time timestamp,
reading frozen<SensorReading>,
Primary Key (name,insertion_time)
)WITH CLUSTERING ORDER BY (insertion_time DESC);
Frozen
• Frozen means that sensor reading can only be overwritten, not
changed a bit at a time
• None frozen UDT’s are coming in 3.0
• A frozen UDT is essentially a blob
13© 2015. All Rights Reserved.
With Multiple sensor readings
• Replace the sensor reading with a map :
14© 2015. All Rights Reserved.
Create table if not exists untypedSensor(
name uuid,
insertion_time timestamp,
readings map <text,frozen<SensorReading>>,
Primary Key (name,insertion_time)
)WITH CLUSTERING ORDER BY (insertion_time DESC);
Meta data
15© 2015. All Rights Reserved.
Create table if not exists untypedSensor(
name uuid,
insertion_time timestamp,
metadata map <text,text>,
readings map <text,frozen<SensorReading>>,
Primary Key (name,insertion_time)
)WITH CLUSTERING ORDER BY (insertion_time DESC);
Writing to our UDT
• Our data will be sent in
JSON format:
• Lets assume we
decode it
16© 2015. All Rights Reserved.
{ "SensorData":
{ "device":"5f388896-71c4-402c-b7c6-8610e305422f",
"insertion_time":"Wed Jan 28 15:54:29 GMT 2015" },
"meta": { "name":"Andy", "latitude":"56.4233156",
"longitude":"-2.9754031" },
"sensors": [
{ "name":"Sensor1", "fValue":"20.1”},
{ "name":"Sensor2", "fValue":"20.2" },
{ "name":"Sensor3", "iValue":"80" },
{ "name":"Sensor4", "sValue":"HIGH!" }
]
}
Quick Steps
17© 2015. All Rights Reserved.
UserType SensorReadingType = null;
SensorReadingType =
cluster.getMetadata().getKeyspace("sensorsync").getUserType("SensorReading");
UDTValue SensorReading = SensorReadingType.newValue();
//Get reading from JSON, Use correct statement depending on type
sensorReading.setFloat("fValue", (float) Value);
//or
sr.setInt("iValue", value);
//etc
18© 2015. All Rights Reserved.
Putting the value into a map and saving
Map<String, UDTValue> mp = new HashMap<String, UDTValue>();
mp.put(Name, sr);
Statement statement = QueryBuilder.insertInto("sensorsync", "Sensors")
.value("name", dUuid)
.value("insertion_time", dd)
.value("reading", mp);
getSession().execute(statement);
Reading back the values
• Select is nothing special
– Select reading where Blah Blah Blah
• Then just get the map
– row.getMap("reading", String.class, UDTValue.class)
19© 2015. All Rights Reserved.
SensorSync Application
• https://github.com/acobley/Sensorsync
– Sensor simulator and Sensor Store
• https://github.com/acobley/SensorWeb
– Displays sensor data on a webpage with D3
• https://github.com/acobley/AirPi
– Python code to read the AirPi and send as Json string
20© 2015. All Rights Reserved.
Conclusion
• Storing Sensor data can be a problem for some Databases
• Cassandra makes it easy with User Defined Types
• Maybe even easier with 2.2 using native JSON support
• INSERT INTO users JSON '{"id": "user123", "age": 42, "state":
"TX"}';
– But that’s another story !
© 2015. All Rights Reserved. 21
Thank you

More Related Content

Similar to Storing Sensor data using User Defined Types

Class5_DataloggerProgrammingArduino.pptx
Class5_DataloggerProgrammingArduino.pptxClass5_DataloggerProgrammingArduino.pptx
Class5_DataloggerProgrammingArduino.pptx
HebaEng
 
Remote Log Analytics Using DDS, ELK, and RxJS
Remote Log Analytics Using DDS, ELK, and RxJSRemote Log Analytics Using DDS, ELK, and RxJS
Remote Log Analytics Using DDS, ELK, and RxJS
Sumant Tambe
 
SensorThings API Webinar - #1 of 4 - Introduction
SensorThings API Webinar - #1 of 4 - IntroductionSensorThings API Webinar - #1 of 4 - Introduction
SensorThings API Webinar - #1 of 4 - Introduction
SensorUp
 
Sql azure cluster dashboard public.ppt
Sql azure cluster dashboard public.pptSql azure cluster dashboard public.ppt
Sql azure cluster dashboard public.ppt
Qingsong Yao
 
OMG Data-Distribution Service Security
OMG Data-Distribution Service SecurityOMG Data-Distribution Service Security
OMG Data-Distribution Service Security
Gerardo Pardo-Castellote
 
Is this normal?
Is this normal?Is this normal?
Is this normal?
Theo Schlossnagle
 
M4M 2 the Rescue of M2M (Eclipse DemoCamp Trondheim)
M4M 2 the Rescue of M2M (Eclipse DemoCamp Trondheim)M4M 2 the Rescue of M2M (Eclipse DemoCamp Trondheim)
M4M 2 the Rescue of M2M (Eclipse DemoCamp Trondheim)
Werner Keil
 
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Paul Brebner
 
Big Data Analytics Strategy and Roadmap
Big Data Analytics Strategy and RoadmapBig Data Analytics Strategy and Roadmap
Big Data Analytics Strategy and Roadmap
Srinath Perera
 
geecon 2013 - Standards for the Future of Java Embedded
geecon 2013 - Standards for the Future of Java Embeddedgeecon 2013 - Standards for the Future of Java Embedded
geecon 2013 - Standards for the Future of Java Embedded
Werner Keil
 
Agile Data Science: Building Hadoop Analytics Applications
Agile Data Science: Building Hadoop Analytics ApplicationsAgile Data Science: Building Hadoop Analytics Applications
Agile Data Science: Building Hadoop Analytics Applications
Russell Jurney
 
Instrumenting the real-time web: Node.js in production
Instrumenting the real-time web: Node.js in productionInstrumenting the real-time web: Node.js in production
Instrumenting the real-time web: Node.js in production
bcantrill
 
Testing the Data Warehouse—Big Data, Big Problems
Testing the Data Warehouse—Big Data, Big ProblemsTesting the Data Warehouse—Big Data, Big Problems
Testing the Data Warehouse—Big Data, Big Problems
TechWell
 
Data Distribution Service Security and the Industrial Internet of Things
Data Distribution Service Security and the Industrial Internet of ThingsData Distribution Service Security and the Industrial Internet of Things
Data Distribution Service Security and the Industrial Internet of Things
Real-Time Innovations (RTI)
 
SAST, fight against potential vulnerabilities
SAST, fight against potential vulnerabilitiesSAST, fight against potential vulnerabilities
SAST, fight against potential vulnerabilities
Andrey Karpov
 
Building a Lightweight Discovery Interface for Chinese Patents, Presented by ...
Building a Lightweight Discovery Interface for Chinese Patents, Presented by ...Building a Lightweight Discovery Interface for Chinese Patents, Presented by ...
Building a Lightweight Discovery Interface for Chinese Patents, Presented by ...
Lucidworks (Archived)
 
Challenges and Opportunities of the IoT Data and Service Interoperability
Challenges and Opportunities of the IoT Data and Service InteroperabilityChallenges and Opportunities of the IoT Data and Service Interoperability
Challenges and Opportunities of the IoT Data and Service Interoperability
SensorUp
 
Agile Data: Building Hadoop Analytics Applications
Agile Data: Building Hadoop Analytics ApplicationsAgile Data: Building Hadoop Analytics Applications
Agile Data: Building Hadoop Analytics Applications
DataWorks Summit
 
soft-shake.ch - Optimizing iOS applications
soft-shake.ch - Optimizing iOS applicationssoft-shake.ch - Optimizing iOS applications
soft-shake.ch - Optimizing iOS applications
soft-shake.ch
 
OSMC 2019 | How to improve database Observability by Charles Judith
OSMC 2019 | How to improve database Observability by Charles JudithOSMC 2019 | How to improve database Observability by Charles Judith
OSMC 2019 | How to improve database Observability by Charles Judith
NETWAYS
 

Similar to Storing Sensor data using User Defined Types (20)

Class5_DataloggerProgrammingArduino.pptx
Class5_DataloggerProgrammingArduino.pptxClass5_DataloggerProgrammingArduino.pptx
Class5_DataloggerProgrammingArduino.pptx
 
Remote Log Analytics Using DDS, ELK, and RxJS
Remote Log Analytics Using DDS, ELK, and RxJSRemote Log Analytics Using DDS, ELK, and RxJS
Remote Log Analytics Using DDS, ELK, and RxJS
 
SensorThings API Webinar - #1 of 4 - Introduction
SensorThings API Webinar - #1 of 4 - IntroductionSensorThings API Webinar - #1 of 4 - Introduction
SensorThings API Webinar - #1 of 4 - Introduction
 
Sql azure cluster dashboard public.ppt
Sql azure cluster dashboard public.pptSql azure cluster dashboard public.ppt
Sql azure cluster dashboard public.ppt
 
OMG Data-Distribution Service Security
OMG Data-Distribution Service SecurityOMG Data-Distribution Service Security
OMG Data-Distribution Service Security
 
Is this normal?
Is this normal?Is this normal?
Is this normal?
 
M4M 2 the Rescue of M2M (Eclipse DemoCamp Trondheim)
M4M 2 the Rescue of M2M (Eclipse DemoCamp Trondheim)M4M 2 the Rescue of M2M (Eclipse DemoCamp Trondheim)
M4M 2 the Rescue of M2M (Eclipse DemoCamp Trondheim)
 
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
Massively Scalable Real-time Geospatial Data Processing with Apache Kafka and...
 
Big Data Analytics Strategy and Roadmap
Big Data Analytics Strategy and RoadmapBig Data Analytics Strategy and Roadmap
Big Data Analytics Strategy and Roadmap
 
geecon 2013 - Standards for the Future of Java Embedded
geecon 2013 - Standards for the Future of Java Embeddedgeecon 2013 - Standards for the Future of Java Embedded
geecon 2013 - Standards for the Future of Java Embedded
 
Agile Data Science: Building Hadoop Analytics Applications
Agile Data Science: Building Hadoop Analytics ApplicationsAgile Data Science: Building Hadoop Analytics Applications
Agile Data Science: Building Hadoop Analytics Applications
 
Instrumenting the real-time web: Node.js in production
Instrumenting the real-time web: Node.js in productionInstrumenting the real-time web: Node.js in production
Instrumenting the real-time web: Node.js in production
 
Testing the Data Warehouse—Big Data, Big Problems
Testing the Data Warehouse—Big Data, Big ProblemsTesting the Data Warehouse—Big Data, Big Problems
Testing the Data Warehouse—Big Data, Big Problems
 
Data Distribution Service Security and the Industrial Internet of Things
Data Distribution Service Security and the Industrial Internet of ThingsData Distribution Service Security and the Industrial Internet of Things
Data Distribution Service Security and the Industrial Internet of Things
 
SAST, fight against potential vulnerabilities
SAST, fight against potential vulnerabilitiesSAST, fight against potential vulnerabilities
SAST, fight against potential vulnerabilities
 
Building a Lightweight Discovery Interface for Chinese Patents, Presented by ...
Building a Lightweight Discovery Interface for Chinese Patents, Presented by ...Building a Lightweight Discovery Interface for Chinese Patents, Presented by ...
Building a Lightweight Discovery Interface for Chinese Patents, Presented by ...
 
Challenges and Opportunities of the IoT Data and Service Interoperability
Challenges and Opportunities of the IoT Data and Service InteroperabilityChallenges and Opportunities of the IoT Data and Service Interoperability
Challenges and Opportunities of the IoT Data and Service Interoperability
 
Agile Data: Building Hadoop Analytics Applications
Agile Data: Building Hadoop Analytics ApplicationsAgile Data: Building Hadoop Analytics Applications
Agile Data: Building Hadoop Analytics Applications
 
soft-shake.ch - Optimizing iOS applications
soft-shake.ch - Optimizing iOS applicationssoft-shake.ch - Optimizing iOS applications
soft-shake.ch - Optimizing iOS applications
 
OSMC 2019 | How to improve database Observability by Charles Judith
OSMC 2019 | How to improve database Observability by Charles JudithOSMC 2019 | How to improve database Observability by Charles Judith
OSMC 2019 | How to improve database Observability by Charles Judith
 

Recently uploaded

一比一原版巴斯大学毕业证(Bath毕业证书)学历如何办理
一比一原版巴斯大学毕业证(Bath毕业证书)学历如何办理一比一原版巴斯大学毕业证(Bath毕业证书)学历如何办理
一比一原版巴斯大学毕业证(Bath毕业证书)学历如何办理
y3i0qsdzb
 
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
nyfuhyz
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
bmucuha
 
University of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma TranscriptUniversity of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma Transcript
soxrziqu
 
原版一比一利兹贝克特大学毕业证(LeedsBeckett毕业证书)如何办理
原版一比一利兹贝克特大学毕业证(LeedsBeckett毕业证书)如何办理原版一比一利兹贝克特大学毕业证(LeedsBeckett毕业证书)如何办理
原版一比一利兹贝克特大学毕业证(LeedsBeckett毕业证书)如何办理
wyddcwye1
 
DSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelinesDSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelines
Timothy Spann
 
Module 1 ppt BIG DATA ANALYTICS_NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS_NOTES FOR MCAModule 1 ppt BIG DATA ANALYTICS_NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS_NOTES FOR MCA
yuvarajkumar334
 
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docxDATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
SaffaIbrahim1
 
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data LakeViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
Walaa Eldin Moustafa
 
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
nuttdpt
 
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
v7oacc3l
 
A presentation that explain the Power BI Licensing
A presentation that explain the Power BI LicensingA presentation that explain the Power BI Licensing
A presentation that explain the Power BI Licensing
AlessioFois2
 
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
hyfjgavov
 
The Ipsos - AI - Monitor 2024 Report.pdf
The  Ipsos - AI - Monitor 2024 Report.pdfThe  Ipsos - AI - Monitor 2024 Report.pdf
The Ipsos - AI - Monitor 2024 Report.pdf
Social Samosa
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
apvysm8
 
"Financial Odyssey: Navigating Past Performance Through Diverse Analytical Lens"
"Financial Odyssey: Navigating Past Performance Through Diverse Analytical Lens""Financial Odyssey: Navigating Past Performance Through Diverse Analytical Lens"
"Financial Odyssey: Navigating Past Performance Through Diverse Analytical Lens"
sameer shah
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
aqzctr7x
 
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
Social Samosa
 
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
xclpvhuk
 
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Aggregage
 

Recently uploaded (20)

一比一原版巴斯大学毕业证(Bath毕业证书)学历如何办理
一比一原版巴斯大学毕业证(Bath毕业证书)学历如何办理一比一原版巴斯大学毕业证(Bath毕业证书)学历如何办理
一比一原版巴斯大学毕业证(Bath毕业证书)学历如何办理
 
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
 
University of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma TranscriptUniversity of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma Transcript
 
原版一比一利兹贝克特大学毕业证(LeedsBeckett毕业证书)如何办理
原版一比一利兹贝克特大学毕业证(LeedsBeckett毕业证书)如何办理原版一比一利兹贝克特大学毕业证(LeedsBeckett毕业证书)如何办理
原版一比一利兹贝克特大学毕业证(LeedsBeckett毕业证书)如何办理
 
DSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelinesDSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelines
 
Module 1 ppt BIG DATA ANALYTICS_NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS_NOTES FOR MCAModule 1 ppt BIG DATA ANALYTICS_NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS_NOTES FOR MCA
 
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docxDATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
 
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data LakeViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
 
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
 
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
 
A presentation that explain the Power BI Licensing
A presentation that explain the Power BI LicensingA presentation that explain the Power BI Licensing
A presentation that explain the Power BI Licensing
 
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
 
The Ipsos - AI - Monitor 2024 Report.pdf
The  Ipsos - AI - Monitor 2024 Report.pdfThe  Ipsos - AI - Monitor 2024 Report.pdf
The Ipsos - AI - Monitor 2024 Report.pdf
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
 
"Financial Odyssey: Navigating Past Performance Through Diverse Analytical Lens"
"Financial Odyssey: Navigating Past Performance Through Diverse Analytical Lens""Financial Odyssey: Navigating Past Performance Through Diverse Analytical Lens"
"Financial Odyssey: Navigating Past Performance Through Diverse Analytical Lens"
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
 
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
 
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
 
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
 

Storing Sensor data using User Defined Types

  • 1. Storing Sensor data using User Defined Types
  • 2. Andy Cobley • Senior lecturer, (Professor), University of Dundee • Program Director of MSc programs in – Data Science (http://www.dundee.ac.uk/study/pg/data-science/ ) – Data Engineering (http://www.dundee.ac.uk/study/pg/data-engineering/ ) 2© 2015. All Rights Reserved.
  • 3. 1 Sensors, Our problem 2 User defined types 3 With collections 4 Reading and Writing Sensor data 3© 2015. All Rights Reserved.
  • 4. Sensors • We were interested in sampling soil moisture (and other values) • At scale • Potentially allows us to calibrate satellites. – Sentinel-1, SMAP • Many existing data sets are very old, especially in developing countries 4© 2015. All Rights Reserved. http://www.ukeof.org.uk/documents/dagsoiltestingkit.pdf
  • 5. Sensors • Soil sensors can be very expensive – Data Loggers can be $100’s • Can have problems with trailing wires – Data muling can overcome that. • We want lots of people to take part (20,000) 5© 2015. All Rights Reserved.
  • 6. Sensors • So: – Lets let people make their own – Raspberry pi and AirPi – Smart Citizen – MudPi 6© 2015. All Rights Reserved.
  • 7. Open Source • Each device sends different data • Airpi: – Temperature, humidity, air pressure, light levels, UV levels, carbon monoxide, nitrogen dioxide and smoke level • Smart Citizen – Carbon Monoxide (CO), Nitrogen Oxide (NO2), Temperature,Humidity,LightSound 7© 2015. All Rights Reserved.
  • 8. Open Source • Each has it’s own source code, data can be sent in different data types – Int, Float, String ? • So we don’t know what each sensor will send or what type it will be. • This was experimental, a kind of what if ? 8© 2015. All Rights Reserved.
  • 9. Relational solutions • We can create relational tables, but we are likely to end up dealing with a lot of nulls. • Decisions we make might go out of date (sensors that send much more data than expected) • You can probably find a relational solution, but it won’t be pretty! 9© 2015. All Rights Reserved.
  • 10. Lets use User Defined Types • Why ? – Allow us to ignore the nulls © 2015. All Rights Reserved. 10
  • 11. User Defined Types 11© 2015. All Rights Reserved. CREATE TYPE if not exists SensorReading ( fValue float, sValue text, iValue int, Accuracy float );
  • 12. If we have one sensor reading 12© 2015. All Rights Reserved. Create table if not exists untypedSensor( name uuid, insertion_time timestamp, reading frozen<SensorReading>, Primary Key (name,insertion_time) )WITH CLUSTERING ORDER BY (insertion_time DESC);
  • 13. Frozen • Frozen means that sensor reading can only be overwritten, not changed a bit at a time • None frozen UDT’s are coming in 3.0 • A frozen UDT is essentially a blob 13© 2015. All Rights Reserved.
  • 14. With Multiple sensor readings • Replace the sensor reading with a map : 14© 2015. All Rights Reserved. Create table if not exists untypedSensor( name uuid, insertion_time timestamp, readings map <text,frozen<SensorReading>>, Primary Key (name,insertion_time) )WITH CLUSTERING ORDER BY (insertion_time DESC);
  • 15. Meta data 15© 2015. All Rights Reserved. Create table if not exists untypedSensor( name uuid, insertion_time timestamp, metadata map <text,text>, readings map <text,frozen<SensorReading>>, Primary Key (name,insertion_time) )WITH CLUSTERING ORDER BY (insertion_time DESC);
  • 16. Writing to our UDT • Our data will be sent in JSON format: • Lets assume we decode it 16© 2015. All Rights Reserved. { "SensorData": { "device":"5f388896-71c4-402c-b7c6-8610e305422f", "insertion_time":"Wed Jan 28 15:54:29 GMT 2015" }, "meta": { "name":"Andy", "latitude":"56.4233156", "longitude":"-2.9754031" }, "sensors": [ { "name":"Sensor1", "fValue":"20.1”}, { "name":"Sensor2", "fValue":"20.2" }, { "name":"Sensor3", "iValue":"80" }, { "name":"Sensor4", "sValue":"HIGH!" } ] }
  • 17. Quick Steps 17© 2015. All Rights Reserved. UserType SensorReadingType = null; SensorReadingType = cluster.getMetadata().getKeyspace("sensorsync").getUserType("SensorReading"); UDTValue SensorReading = SensorReadingType.newValue(); //Get reading from JSON, Use correct statement depending on type sensorReading.setFloat("fValue", (float) Value); //or sr.setInt("iValue", value); //etc
  • 18. 18© 2015. All Rights Reserved. Putting the value into a map and saving Map<String, UDTValue> mp = new HashMap<String, UDTValue>(); mp.put(Name, sr); Statement statement = QueryBuilder.insertInto("sensorsync", "Sensors") .value("name", dUuid) .value("insertion_time", dd) .value("reading", mp); getSession().execute(statement);
  • 19. Reading back the values • Select is nothing special – Select reading where Blah Blah Blah • Then just get the map – row.getMap("reading", String.class, UDTValue.class) 19© 2015. All Rights Reserved.
  • 20. SensorSync Application • https://github.com/acobley/Sensorsync – Sensor simulator and Sensor Store • https://github.com/acobley/SensorWeb – Displays sensor data on a webpage with D3 • https://github.com/acobley/AirPi – Python code to read the AirPi and send as Json string 20© 2015. All Rights Reserved.
  • 21. Conclusion • Storing Sensor data can be a problem for some Databases • Cassandra makes it easy with User Defined Types • Maybe even easier with 2.2 using native JSON support • INSERT INTO users JSON '{"id": "user123", "age": 42, "state": "TX"}'; – But that’s another story ! © 2015. All Rights Reserved. 21

Editor's Notes

  1. We know about “Flower Power”, but it wasn’t an option then.