gd_bam 0.1.25 → 0.1.26

Sign up to get free protection for your applications and to get access to all the features.
data/lib/bam/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bam
2
- VERSION = '0.1.25'
2
+ VERSION = '0.1.26'
3
3
  end
data/lib/base/sink.rb CHANGED
@@ -21,6 +21,10 @@ module GoodData
21
21
  sink[:fields].find_all {|f| f[:type] == "date"}
22
22
  end
23
23
 
24
+ def self.get_fact_fields(sink)
25
+ sink[:fields].find_all {|f| f[:type] == "fact"}
26
+ end
27
+
24
28
  def self.add_target_type(sink)
25
29
  target = sink[:target].to_s
26
30
  path = Pathname(target)
@@ -82,6 +82,14 @@ module GoodData
82
82
  metadata(builder, sf_description)
83
83
  end
84
84
 
85
+ # prepares a sink for sinking into GD. This means dealing with stuff like scientific notation which is handled bu uploading as a decimal and not string
86
+ def self.sink_out_gd_metadata(metadata, sink)
87
+ metadata_fields = metadata[:fields]
88
+ sink_facts = GoodData::Bam::Sink.get_fact_fields(sink).map {|f| f[:meta]}
89
+ x = metadata_fields.map {|f| sink_facts.include?(f[:name]) ? f.merge({:type => "decimal"}) : f}
90
+ GoodData::Bam::Metadata.create(metadata.merge({:fields => x}))
91
+ end
92
+
85
93
  def self.metadata(builder, description)
86
94
  builder.Record({
87
95
  :fieldDelimiter => description[:fieldDelimiter],
@@ -108,13 +108,17 @@ module GoodData
108
108
  builder.Metadata({:id => "load_metadata"}) do |builder|
109
109
  Helpers::csv_metadata(builder, state[:metadata][input_name])
110
110
  end
111
+ builder.Metadata({:id => "gd_sink_metadata"}) do |builder|
112
+ Helpers::csv_metadata(builder, Helpers::sink_out_gd_metadata(state[:metadata][input_name], sink))
113
+ end
114
+
111
115
  end
112
116
 
113
117
  builder.Phase(:number => 0) do
114
118
  gd_dataset = sink[:gd_name] || sink[:id]
115
119
  to_svinstvo = GoodData::CloverGenerator::build_gd_dataset_loader_json(sink)
116
120
  Core::build_node2(builder, Nodes.reader2({:name => "CSV Loader", :id => "loader", :fileURL => "${PROJECT}/data/#{input_name}.csv"}))
117
- Core::build_node2(builder, Nodes.edge2({:toNode => "gd_load:0", :fromNode => "reformat:0", :metadata => "load_metadata"}))
121
+ Core::build_node2(builder, Nodes.edge2({:toNode => "gd_load:0", :fromNode => "reformat:0", :metadata => "gd_sink_metadata"}))
118
122
 
119
123
  transform = <<HEREDOC
120
124
  function string gd_date_compliance(string a_date) {
@@ -127,12 +131,20 @@ function string gd_date_compliance(string a_date) {
127
131
  return a_date;
128
132
  }
129
133
 
134
+ function decimal deal_with_scientific_notation(string a_number) {
135
+ return str2decimal(a_number);
136
+ }
137
+
130
138
  function integer transform() {
131
139
  $out.0.* = $in.0.*;
132
140
  #{Sink.get_date_fields(sink).map do |f|
133
141
  "$out.0.#{f[:meta]} = gd_date_compliance($in.0.#{f[:meta]});"
134
142
  end.join("\n")}
135
143
 
144
+ #{Sink.get_fact_fields(sink).map do |f|
145
+ "$out.0.#{f[:meta]} = deal_with_scientific_notation($in.0.#{f[:meta]});"
146
+ end.join("\n")}
147
+
136
148
  return ALL;
137
149
  }
138
150
  HEREDOC
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gd_bam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.25
4
+ version: 0.1.26
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-27 00:00:00.000000000 Z
12
+ date: 2013-09-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake