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
49529100
Commit
49529100
authored
Nov 14, 2018
by
王志伟
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://git.wanmeizhensuo.com/ML/ffm-baseline
parents
3e4f9e7f
d0595be5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
10 deletions
+20
-10
test.py
local/test.py
+20
-10
No files found.
local/test.py
View file @
49529100
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://rm-m5e842126ng59jrv6.mysql.rds.aliyuncs.com:3306/doris_prod"
,
driver
=
"com.mysql.jdbc.Driver"
,
dbtable
=
"device diary_queue"
,
user
=
"doris"
,
password
=
"o5gbA27hXHHm"
)
.
load
()
# 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