Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
ffm-baseline
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ML
ffm-baseline
Commits
4de7681c
Commit
4de7681c
authored
Nov 14, 2018
by
张彦钊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改测试文件
parent
5acbce0e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
10 deletions
+16
-10
test.py
local/test.py
+16
-10
No files found.
local/test.py
View file @
4de7681c
from
__future__
import
print_function
from
utils
import
con_sql
import
datetime
import
time
import
pymysql
from
pyspark.sql
import
SparkSession
from
pyspark.sql
import
SQLContext
def
fetch_data
(
start_date
,
end_date
):
spark
=
SparkSession
\
.
builder
\
.
appName
(
"get_data"
)
\
sc
=
SparkSession
.
builder
.
appName
(
"Python Spark SQL basic example"
)
\
.
config
(
'spark.some.config,option0'
,
'some-value'
)
\
.
getOrCreate
()
sql
=
"select cid,device_id,stat_date from data_feed_click "
\
"where stat_date >= '{0}' and stat_date <= '{1}'"
.
format
(
start_date
,
end_date
)
df
=
spark
.
sql
(
sql
)
.
na
.
drop
()
.
distinct
device_id
=
df
.
select
(
"device_id"
)
.
collect
()
ctx
=
SQLContext
(
sc
)
df
=
ctx
.
read
.
format
(
"jdbc"
)
.
options
(
url
=
"jdbc:mysql://192.168.15.12:4000/jerry_prod"
,
driver
=
"com.mysql.jdbc.Driver"
,
dbtable
=
"data_feed_click"
,
user
=
"root"
,
password
=
"3SYz54LS9#^9sBvC"
)
.
load
()
df
.
show
(
6
)
# url = "jdbc:mysql://10.66.157.22:4000/jerry_prod"
# table = "data_feed_click"
# properties = {"user": "root", "password": "3SYz54LS9#^9sBvC"}
# df = sqlContext.read.jdbc(url, table, properties)
print
(
"成功获取点击表里的数据"
)
print
(
device_id
[
0
:
2
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment