-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathhelp.txt
93 lines (78 loc) · 3.3 KB
/
help.txt
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
Success! Kerberos is now running. You can enable Kerberos in a Cloudera Manager
cluster from the drop-down menu for that cluster on the CM home page. It will
ask you to confirm that this script performed the following steps:
* set up a working KDC.
* checked that the KDC allows renewable tickets.
* installed the client libraries.
* created a proper account for Cloudera Manager.
Then, it will prompt you for the following details (accept defaults if not
specified here):
KDC Type: MIT KDC
KDC Server Host: quickstart.cloudera
Kerberos Security Realm: CLOUDERA
Later, it will prompt you for KDC account manager credentials:
Username: cloudera-scm/admin (@ CLOUDERA)
Password: cloudera
[cloudera@quickstart ~]$
import org.json.JSONArray;
import org.json.JSONObject;
import java.sql.ResultSet;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;
/**
* Utility for converting ResultSets into some Output formats
*/
public class Convertor {
/**
* Convert a result set into a JSON Array
* @param resultSet
* @return a JSONArray
* @throws Exception
*/
public static JSONArray convertResultSetIntoJSON(ResultSet resultSet) throws Exception {
JSONArray jsonArray = new JSONArray();
while (resultSet.next()) {
int total_rows = resultSet.getMetaData().getColumnCount();
JSONObject obj = new JSONObject();
for (int i = 0; i < total_rows; i++) {
String columnName = resultSet.getMetaData().getColumnLabel(i + 1).toLowerCase();
Object columnValue = resultSet.getObject(i + 1);
// if value in DB is null, then we set it to default value
if (columnValue == null){
columnValue = "null";
}
/*
Next if block is a hack. In case when in db we have values like price and price1 there's a bug in jdbc -
both this names are getting stored as price in ResulSet. Therefore when we store second column value,
we overwrite original value of price. To avoid that, i simply add 1 to be consistent with DB.
*/
if (obj.has(columnName)){
columnName += "1";
}
obj.put(columnName, columnValue);
}
jsonArray.put(obj);
}
return jsonArray;
}
public static int converBooleanIntoInt(boolean bool){
if (bool) return 1;
else return 0;
}
public static int convertBooleanStringIntoInt(String bool){
if (bool.equals("false")) return 0;
else if (bool.equals("true")) return 1;
else {
throw new IllegalArgumentException("wrong value is passed to the method. Value is "+bool);
}
}
public static double getDoubleOutOfString(String value, String format, Locale locale){
DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(locale);
otherSymbols.setDecimalSeparator('.');
DecimalFormat f = new DecimalFormat(format,otherSymbols);
String formattedValue = f.format(Double.parseDouble(value));
double number = Double.parseDouble(formattedValue);
return Math.round(number * 100.0) / 100.0;
}
}