-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathsampleparser.fsx
41 lines (35 loc) · 1.37 KB
/
sampleparser.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#load @".paket\load\windowsazure.storage.fsx"
module Raw =
type Column = { Column : string; Type : string; Optional : bool }
type Table = { Table : string; Columns : Column array }
type Schema = { Tables : Table array }
module Parsed =
open System
open Microsoft.WindowsAzure.Storage.Table
let parseEdmType (value:string) =
match value.ToLower() with
| "binary" -> EdmType.Binary
| "boolean" -> EdmType.Boolean
| "datetime" -> EdmType.DateTime
| "double" -> EdmType.Double
| "guid" -> EdmType.Guid
| "int32" -> EdmType.Int32
| "int64" -> EdmType.Int64
| "string" -> EdmType.String
| value -> failwithf "Unknown column type '%s'" value
type Column = { Column : string; Type : EdmType; Optional : bool }
type Table = { Table : string; Columns : Column array }
type Schema = { Tables : Table array }
open Newtonsoft.Json
let schema =
let schema = JsonConvert.DeserializeObject<Raw.Schema>(System.IO.File.ReadAllText "table-schema.json")
{ Parsed.Schema.Tables =
schema.Tables
|> Array.map(fun t ->
{ Table = t.Table
Columns =
t.Columns
|> Array.map(fun c ->
{ Column = c.Column
Type = Parsed.parseEdmType c.Type
Optional = c.Optional }) }) }