質問編集履歴
9
dty
test
CHANGED
File without changes
|
test
CHANGED
@@ -44,17 +44,17 @@
|
|
44
44
|
|
45
45
|
for line in lines2:
|
46
46
|
|
47
|
-
|
47
|
+
from impala.dbapi import connect
|
48
48
|
|
49
|
-
|
49
|
+
conn = connect(host='172.16.102.6', port=21050) #接続
|
50
50
|
|
51
|
-
|
51
|
+
cur = conn.cursor()
|
52
52
|
|
53
|
-
|
53
|
+
cur.execute('use tse_d_yf') #テーブルの選択
|
54
54
|
|
55
|
-
|
55
|
+
cur.execute('SELECT * from sec1 where code_id = \'int(line)\' limit 10 ') #select
|
56
56
|
|
57
|
-
|
57
|
+
cur.fetchall() #全ての結果を返すexit()
|
58
58
|
|
59
59
|
|
60
60
|
|
8
a
test
CHANGED
File without changes
|
test
CHANGED
@@ -44,7 +44,7 @@
|
|
44
44
|
|
45
45
|
for line in lines2:
|
46
46
|
|
47
|
-
from impala.dbapi import connect
|
47
|
+
from impala.dbapi import connect
|
48
48
|
|
49
49
|
conn = connect(host='172.16.102.6', port=21050) #接続
|
50
50
|
|
7
so-suko-do
test
CHANGED
File without changes
|
test
CHANGED
@@ -44,7 +44,7 @@
|
|
44
44
|
|
45
45
|
for line in lines2:
|
46
46
|
|
47
|
-
from impala.dbapi import connect
|
47
|
+
from impala.dbapi import connect
|
48
48
|
|
49
49
|
conn = connect(host='172.16.102.6', port=21050) #接続
|
50
50
|
|
6
コメント追加。
test
CHANGED
File without changes
|
test
CHANGED
@@ -38,23 +38,23 @@
|
|
38
38
|
|
39
39
|
f = open('/home/user/bootcamp/StockCode.txt')
|
40
40
|
|
41
|
-
lines2 = f.readlines()
|
41
|
+
lines2 = f.readlines() # 1行毎にファイル終端まで全て読む(改行文字も含まれる)
|
42
42
|
|
43
|
-
f.close()
|
43
|
+
f.close() # lines2: リスト。要素は1行の文字列データ
|
44
44
|
|
45
45
|
for line in lines2:
|
46
46
|
|
47
47
|
from impala.dbapi import connect
|
48
48
|
|
49
|
-
conn = connect(host='172.16.102.6', port=21050)
|
49
|
+
conn = connect(host='172.16.102.6', port=21050) #接続
|
50
50
|
|
51
51
|
cur = conn.cursor()
|
52
52
|
|
53
|
-
cur.execute('use tse_d_yf')
|
53
|
+
cur.execute('use tse_d_yf') #テーブルの選択
|
54
54
|
|
55
|
-
cur.execute('SELECT * from sec1 where code_id = \'int(line)\' limit 10 ')
|
55
|
+
cur.execute('SELECT * from sec1 where code_id = \'int(line)\' limit 10 ') #select
|
56
56
|
|
57
|
-
cur.fetchall()
|
57
|
+
cur.fetchall() #全ての結果を返すexit()
|
58
58
|
|
59
59
|
|
60
60
|
|
@@ -70,15 +70,15 @@
|
|
70
70
|
|
71
71
|
from impala.dbapi import connect
|
72
72
|
|
73
|
-
conn = connect(host='172.16.102.6', port=21050)
|
73
|
+
conn = connect(host='172.16.102.6', port=21050) #接続
|
74
74
|
|
75
75
|
cur = conn.cursor()
|
76
76
|
|
77
|
-
cur.execute('use tse_d_yf')
|
77
|
+
cur.execute('use tse_d_yf') #テーブルの選択
|
78
78
|
|
79
|
-
cur.execute('SELECT * from sec1 where code_id = \'9007\' limit 10 ')
|
79
|
+
cur.execute('SELECT * from sec1 where code_id = \'9007\' limit 10 ') #select
|
80
80
|
|
81
|
-
cur.fetchall()
|
81
|
+
cur.fetchall() #全ての結果を返すexit()
|
82
82
|
|
83
83
|
```
|
84
84
|
|
@@ -92,23 +92,23 @@
|
|
92
92
|
|
93
93
|
f = open('/home/user/bootcamp/StockCode.txt')
|
94
94
|
|
95
|
-
lines2 = f.readlines()
|
95
|
+
lines2 = f.readlines() # 1行毎にファイル終端まで全て読む(改行文字も含まれる)
|
96
96
|
|
97
|
-
f.close()
|
97
|
+
f.close() # lines2: リスト。要素は1行の文字列データ
|
98
98
|
|
99
99
|
for line in lines2:
|
100
100
|
|
101
101
|
from impala.dbapi import connect
|
102
102
|
|
103
|
-
conn = connect(host='172.16.102.6', port=21050)
|
103
|
+
conn = connect(host='172.16.102.6', port=21050) #接続
|
104
104
|
|
105
105
|
cur = conn.cursor()
|
106
106
|
|
107
|
-
cur.execute('use tse_d_yf')
|
107
|
+
cur.execute('use tse_d_yf') #テーブルの選択
|
108
108
|
|
109
|
-
cur.execute('SELECT * from sec1 where code_id = \'?\' limit 10 ', line)
|
109
|
+
cur.execute('SELECT * from sec1 where code_id = \'?\' limit 10 ', line) #select
|
110
110
|
|
111
|
-
cur.fetchall()
|
111
|
+
cur.fetchall() #全ての結果を返すexit()
|
112
112
|
|
113
113
|
```
|
114
114
|
|
5
ソースコード改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -44,7 +44,7 @@
|
|
44
44
|
|
45
45
|
for line in lines2:
|
46
46
|
|
47
|
-
from impala.dbapi import connect
|
47
|
+
from impala.dbapi import connect
|
48
48
|
|
49
49
|
conn = connect(host='172.16.102.6', port=21050)
|
50
50
|
|
@@ -98,17 +98,17 @@
|
|
98
98
|
|
99
99
|
for line in lines2:
|
100
100
|
|
101
|
-
from impala.dbapi import connect
|
101
|
+
from impala.dbapi import connect
|
102
102
|
|
103
|
-
conn = connect(host='172.16.102.6', port=21050)
|
103
|
+
conn = connect(host='172.16.102.6', port=21050)
|
104
104
|
|
105
|
-
cur = conn.cursor()
|
105
|
+
cur = conn.cursor()
|
106
106
|
|
107
|
-
cur.execute('use tse_d_yf')
|
107
|
+
cur.execute('use tse_d_yf')
|
108
108
|
|
109
|
-
cur.execute('SELECT * from sec1 where code_id = \'?\' limit 10 ', line)
|
109
|
+
cur.execute('SELECT * from sec1 where code_id = \'?\' limit 10 ', line)
|
110
110
|
|
111
|
-
cur.fetchall()
|
111
|
+
cur.fetchall()
|
112
112
|
|
113
113
|
```
|
114
114
|
|
4
試してみたこと③追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -62,9 +62,9 @@
|
|
62
62
|
|
63
63
|
###試したこと
|
64
64
|
|
65
|
-
|
65
|
+
①型をstrにしてみてもダメでした。
|
66
66
|
|
67
|
-
|
67
|
+
②ループのところをSQLだけ実行する。
|
68
68
|
|
69
69
|
```ここに言語を入力
|
70
70
|
|
@@ -86,6 +86,62 @@
|
|
86
86
|
|
87
87
|
[('9007', '20150403', Decimal('1255.00'), Decimal('1257.00'), Decimal('1239.00'), Decimal('1244.00'), 1292000.0, Decimal('1244.00'), '9007'), ('9007', '20150402', Decimal('1236.00'), Decimal('1279.00'), Decimal('1236.00'), Decimal('1262.00'), 1994000.0, Decimal('1262.00'), '9007'), ('9007', '20150401', Decimal('1216.00'), Decimal('1235.00'), Decimal('1200.00'), Decimal('1221.00'), 2214000.0, Decimal('1221.00'), '9007'), ('9007', '20150331', Decimal('1275.00'), Decimal('1279.00'), Decimal('1225.00'), Decimal('1225.00'), 2020000.0, Decimal('1225.00'), '9007'), ('9007', '20150330', Decimal('1273.00'), Decimal('1291.00'), Decimal('1267.00'), Decimal('1271.00'), 1439000.0, Decimal('1271.00'), '9007'), ('9007', '20150327', Decimal('1300.00'), Decimal('1312.00'), Decimal('1255.00'), Decimal('1268.00'), 2474000.0, Decimal('1268.00'), '9007'), ('9007', '20150326', Decimal('1336.00'), Decimal('1336.00'), Decimal('1308.00'), Decimal('1311.00'), 2571000.0, Decimal('1311.00'), '9007'), ('9007', '20150325', Decimal('1327.00'), Decimal('1343.00'), Decimal('1326.00'), Decimal('1341.00'), 1506000.0, Decimal('1341.00'), '9007'), ('9007', '20150324', Decimal('1336.00'), Decimal('1338.00'), Decimal('1317.00'), Decimal('1336.00'), 1692000.0, Decimal('1336.00'), '9007'), ('9007', '20150323', Decimal('1344.00'), Decimal('1348.00'), Decimal('1335.00'), Decimal('1343.00'), 1095000.0, Decimal('1343.00'), '9007')]
|
88
88
|
|
89
|
+
③code_id=の変数を?にしてみる。
|
90
|
+
|
91
|
+
```ここに言語を入力
|
92
|
+
|
93
|
+
f = open('/home/user/bootcamp/StockCode.txt')
|
94
|
+
|
95
|
+
lines2 = f.readlines()
|
96
|
+
|
97
|
+
f.close()
|
98
|
+
|
99
|
+
for line in lines2:
|
100
|
+
|
101
|
+
from impala.dbapi import connect
|
102
|
+
|
103
|
+
conn = connect(host='172.16.102.6', port=21050)
|
104
|
+
|
105
|
+
cur = conn.cursor()
|
106
|
+
|
107
|
+
cur.execute('use tse_d_yf')
|
108
|
+
|
109
|
+
cur.execute('SELECT * from sec1 where code_id = \'?\' limit 10 ', line)
|
110
|
+
|
111
|
+
cur.fetchall()
|
112
|
+
|
113
|
+
```
|
114
|
+
|
115
|
+
実行結果
|
116
|
+
|
117
|
+
Traceback (most recent call last):
|
118
|
+
|
119
|
+
File "<stdin>", line 6, in <module>
|
120
|
+
|
121
|
+
File "/usr/local/lib/python2.7/dist-packages/impala/hiveserver2.py", line 248, in execute
|
122
|
+
|
123
|
+
configuration=configuration)
|
124
|
+
|
125
|
+
File "/usr/local/lib/python2.7/dist-packages/impala/hiveserver2.py", line 289, in execute_async
|
126
|
+
|
127
|
+
self._execute_async(op)
|
128
|
+
|
129
|
+
File "/usr/local/lib/python2.7/dist-packages/impala/hiveserver2.py", line 308, in _execute_async
|
130
|
+
|
131
|
+
operation_fn()
|
132
|
+
|
133
|
+
File "/usr/local/lib/python2.7/dist-packages/impala/hiveserver2.py", line 280, in op
|
134
|
+
|
135
|
+
parameters)
|
136
|
+
|
137
|
+
File "/usr/local/lib/python2.7/dist-packages/impala/interface.py", line 262, in _bind_parameters
|
138
|
+
|
139
|
+
raise ProgrammingError("Query parameters argument should be a "
|
140
|
+
|
141
|
+
impala.error.ProgrammingError: Query parameters argument should be a list, tuple, or dict object
|
142
|
+
|
143
|
+
|
144
|
+
|
89
145
|
|
90
146
|
|
91
147
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
3
・ループのところをSQLだけ実行する
test
CHANGED
File without changes
|
test
CHANGED
@@ -62,7 +62,29 @@
|
|
62
62
|
|
63
63
|
###試したこと
|
64
64
|
|
65
|
-
型をstrにしてみてもダメでした。
|
65
|
+
・型をstrにしてみてもダメでした。
|
66
|
+
|
67
|
+
・ループのところをSQLだけ実行する。
|
68
|
+
|
69
|
+
```ここに言語を入力
|
70
|
+
|
71
|
+
from impala.dbapi import connect
|
72
|
+
|
73
|
+
conn = connect(host='172.16.102.6', port=21050)
|
74
|
+
|
75
|
+
cur = conn.cursor()
|
76
|
+
|
77
|
+
cur.execute('use tse_d_yf')
|
78
|
+
|
79
|
+
cur.execute('SELECT * from sec1 where code_id = \'9007\' limit 10 ')
|
80
|
+
|
81
|
+
cur.fetchall()
|
82
|
+
|
83
|
+
```
|
84
|
+
|
85
|
+
実行結果
|
86
|
+
|
87
|
+
[('9007', '20150403', Decimal('1255.00'), Decimal('1257.00'), Decimal('1239.00'), Decimal('1244.00'), 1292000.0, Decimal('1244.00'), '9007'), ('9007', '20150402', Decimal('1236.00'), Decimal('1279.00'), Decimal('1236.00'), Decimal('1262.00'), 1994000.0, Decimal('1262.00'), '9007'), ('9007', '20150401', Decimal('1216.00'), Decimal('1235.00'), Decimal('1200.00'), Decimal('1221.00'), 2214000.0, Decimal('1221.00'), '9007'), ('9007', '20150331', Decimal('1275.00'), Decimal('1279.00'), Decimal('1225.00'), Decimal('1225.00'), 2020000.0, Decimal('1225.00'), '9007'), ('9007', '20150330', Decimal('1273.00'), Decimal('1291.00'), Decimal('1267.00'), Decimal('1271.00'), 1439000.0, Decimal('1271.00'), '9007'), ('9007', '20150327', Decimal('1300.00'), Decimal('1312.00'), Decimal('1255.00'), Decimal('1268.00'), 2474000.0, Decimal('1268.00'), '9007'), ('9007', '20150326', Decimal('1336.00'), Decimal('1336.00'), Decimal('1308.00'), Decimal('1311.00'), 2571000.0, Decimal('1311.00'), '9007'), ('9007', '20150325', Decimal('1327.00'), Decimal('1343.00'), Decimal('1326.00'), Decimal('1341.00'), 1506000.0, Decimal('1341.00'), '9007'), ('9007', '20150324', Decimal('1336.00'), Decimal('1338.00'), Decimal('1317.00'), Decimal('1336.00'), 1692000.0, Decimal('1336.00'), '9007'), ('9007', '20150323', Decimal('1344.00'), Decimal('1348.00'), Decimal('1335.00'), Decimal('1343.00'), 1095000.0, Decimal('1343.00'), '9007')]
|
66
88
|
|
67
89
|
|
68
90
|
|
2
codeで囲む
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,6 +34,8 @@
|
|
34
34
|
|
35
35
|
|
36
36
|
|
37
|
+
```ここに言語を入力
|
38
|
+
|
37
39
|
f = open('/home/user/bootcamp/StockCode.txt')
|
38
40
|
|
39
41
|
lines2 = f.readlines()
|
@@ -56,6 +58,8 @@
|
|
56
58
|
|
57
59
|
|
58
60
|
|
61
|
+
```
|
62
|
+
|
59
63
|
###試したこと
|
60
64
|
|
61
65
|
型をstrにしてみてもダメでした。
|
1
タイトル修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
銘柄コード一覧ファイル(StockCode.txt)を順に読み込み,impalaを用いて 株価データをダウンロードするpythonコードを作成
|
1
|
+
pythonで銘柄コード一覧ファイル(StockCode.txt)を順に読み込み,impalaを用いて 株価データをダウンロードするpythonコードを作成
|
test
CHANGED
File without changes
|