Repository navigation
Expand file tree
/
Copy pathLambda.java
More file actions
255 lines (226 loc) · 7.83 KB
/
Copy pathLambda.java
File metadata and controls
255 lines (226 loc) · 7.83 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*******************************************************************************
* Copyright 2015 Defense Health Agency (DHA)
*
* If your use of this software does not include any GPLv2 components:
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ----------------------------------------------------------------------------
* If your use of this software includes any GPLv2 components:
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*******************************************************************************/
package prerna.reactor;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
import prerna.algorithm.api.ITableDataFrame;
import prerna.ds.QueryStruct;
import prerna.engine.api.IHeadersDataRow;
import prerna.sablecc2.om.Filter;
import prerna.sablecc2.om.GenRowStruct;
import prerna.sablecc2.om.Join;
import prerna.sablecc2.om.PixelDataType;
import prerna.sablecc2.om.nounmeta.NounMetadata;
public class Lambda implements Iterator{
// this is the map class - yeah well no shit
// eventually we can make it extend the whole spark stuff
// First is the options object which can be accessed through
// getOption
// The input is always a row iterator IHeadersDataRow
// seems like I need a new implementation for it
// I need a set query function which will pull all the data that is needed
// The function will work through each of the information
// store is where you can keep variable outside of the map if you want to
public Hashtable <String, Object> options = new Hashtable <String, Object>();
public Hashtable <String, Object> store = new Hashtable <String, Object>();
public String query = null;
public ITableDataFrame frame = null;
public QueryStruct qs = null;
Iterator <IHeadersDataRow> thisIterator = null;
public Vector<String> strVector = null;
public Vector<Double> decVector = null;
public Vector<String> cols = null;
public Vector<Object> filters = null;
public Vector<Object> joins = null;
// all the input strings are stored here
public Hashtable <String, String[]> inputStore = new Hashtable<String, String[]>();
public IHeadersDataRow RESULT = null;
public void mergeQueryStruct(QueryStruct incomingQS) {
// if
}
public void makeQuery()
{
// this will be overridden
System.out.println("Making Query Struct");
String tableName = "";
if(this.frame != null)
tableName = frame.getName();
// need to think about the as here
if(cols != null)
{
for(int colIndex = 0;cols != null && colIndex < cols.size();colIndex++)
{
String input = cols.elementAt(colIndex);
String [] column = input.split("__");
if(column.length == 1)
qs.addSelector(tableName , input);
else
qs.addSelector(tableName , input);
}
}
if(filters != null)
{
for(int filterIndex = 0;filterIndex < filters.size();filterIndex++)
{
Filter filter = (Filter)filters.elementAt(filterIndex);
GenRowStruct values = filter.getRComparison();
if(values.size() > 0)
{
// predict what the type is
PixelDataType type = values.vector.get(1).getNounType();
String pad = "";
if(type == PixelDataType.CONST_STRING)
{
Vector <String> strVector = new Vector<String>();
// now make this into a vector
for(int valIndex = 1;valIndex < values.size();valIndex++)
strVector.addElement(values.get(valIndex)+"");
qs.addFilter(filter.getLComparison().get(0).toString(), filter.getComparator(), strVector);
}
else
{
Vector <Double> decVector = new Vector<Double>();
for(int valIndex = 1;valIndex < values.size();valIndex++)
{
Object doubVal = values.get(valIndex);
decVector.addElement(new Double(" + values.elementAt(valIndex) +"));
}
qs.addFilter(filter.getLComparison().get(0).toString(), filter.getComparator(), decVector);
}
}
}
}
if(joins != null)
{
for(int joinIndex = 0; joinIndex < joins.size();joinIndex++)
{
Join join = (Join)joins.elementAt(joinIndex);
qs.addRelation(join.getLColumn() , join.getRColumn(), join.getJoinType());
}
}
if(frame != null) {
//TODO: UPDATE FOR NEW QS
//TODO: UPDATE FOR NEW QS
//TODO: UPDATE FOR NEW QS
//TODO: UPDATE FOR NEW QS
//TODO: UPDATE FOR NEW QS
//TODO: UPDATE FOR NEW QS
// thisIterator = frame.query(qs);
}
}
public void addInputs()
{
// this will be overridden
}
public IHeadersDataRow executeCode(IHeadersDataRow row)
{
// this will be overridden
return null;
}
public void setVar(String variableName, Object value)
{
store.put(variableName, value);
}
public void addStore(Hashtable <String, Object> newStore)
{
Enumeration <String> keys = newStore.keys();
while(keys.hasMoreElements())
{
String key = keys.nextElement();
this.store.put(key, newStore.get(key));
}
}
public void setFrame(ITableDataFrame frame)
{
this.frame = frame;
}
public Object getVar(String variableName)
{
return store.get(variableName);
}
public NounMetadata execute()
{
// run the query
// get the headerrow
// call the map with every headerrow
// this iterator needs to be chhanged to something different
// need something to get the headers so I know the cardinality eventually
if(thisIterator == null)
{
System.out.println("NOthing to process");
executeCode(null);
return null;
}
while(thisIterator.hasNext())
{
IHeadersDataRow row = (IHeadersDataRow)thisIterator.next();
executeCode(row);
}
return null;
}
public boolean hasNext()
{
return thisIterator.hasNext();
}
public IHeadersDataRow next()
{
IHeadersDataRow row = (IHeadersDataRow)thisIterator.next();
return executeCode(row);
}
// for now I am assuming the curRow is a hashtable
public Object[] getRow(String inputStringRef, IHeadersDataRow curRow)
{
String [] inputStrings = inputStore.get(inputStringRef);
Object [] retRow = new Object[inputStrings.length];
// aligns it based on the input string
// need to take all the data and align the values based on inputStrings
for(int inputIndex = 0;inputIndex < inputStrings.length;inputIndex++)
{
retRow[inputIndex] = curRow.getField(inputStrings[inputIndex]);
// try to set it from store if it is null
if(retRow[inputIndex] == null)
retRow[inputIndex] = store.get(inputStrings[inputIndex]);
}
return retRow;
}
public Object[] map(Object [] row)
{
// this is where the code would sit
// I would actually put this method
Object [] retRow = row;
// take the existing data and format it in a way that is useful for us to send it for processing
// then send it back
return retRow;
}
public void test()
{
System.out.println("Hello Lambda !!");
}
}