-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
readme, tispark: update TiSpark and enable sparkR and pyspark #27
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,3 +180,12 @@ scala> spark.sql("select count(*) from lineitem").show | |
| 60175| | ||
+--------+ | ||
``` | ||
|
||
You can also access Spark with Python or R using following commands: | ||
|
||
``` | ||
docker-compose exec tispark-master /opt/spark/bin/pyspark | ||
docker-compose exec tispark-master /opt/spark/bin/sparkR | ||
``` | ||
|
||
More document about TiSpark can be found [here](https://github.com/pingcap/tispark). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. document -> documents ("document" is a countable noun) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Package: TiSparkR | ||
Type: Package | ||
Title: TiSpark for R | ||
Version: 1.1 | ||
Author: PingCAP | ||
Maintainer: Novemser <novemser@gmail.com> | ||
Description: A shabby thin layer to support TiSpark in R language. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm... "shabby" generally has a fairly negative connotation. Are you sure that's what is desired? |
||
License: Apache 2.0 | ||
Copyright: 2017 PingCAP, Inc. | ||
Encoding: UTF-8 | ||
LazyData: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exportPattern("^[[:alpha:]]+") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# | ||
# Copyright 2017 PingCAP, Inc. | ||
# | ||
# 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, | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# | ||
|
||
# Title : TiSparkR | ||
# Objective : TiSpark entry for R | ||
# Created by: novemser | ||
# Created on: 17-11-1 | ||
|
||
# Function:createTiContext | ||
# Create a new TiContext via the spark session passed in | ||
# | ||
# @return A new TiContext created on session | ||
# @param session A Spark Session for TiContext creation | ||
createTiContext <- function(session) { | ||
sparkR.newJObject("org.apache.spark.sql.TiContext", session) | ||
} | ||
|
||
# Function:tidbMapDatabase | ||
# Mapping TiContext designated database to `dbName`. | ||
# | ||
# @param tiContext TiSpark context | ||
# @param dbName Database name to map | ||
# @param isPrefix Whether to use dbName As Prefix | ||
# @param loadStatistics Whether to use statistics information from TiDB | ||
tidbMapDatabase <- function(tiContext, dbName, isPrefix=FALSE, loadStatistics=TRUE) { | ||
sparkR.callJMethod(tiContext, "tidbMapDatabase", dbName, isPrefix, loadStatistics) | ||
paste("Mapping to database:", dbName) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
## TiSparkR | ||
A thin layer build for supporting R language with TiSpark | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -> TiSparkR is a thin layer built to support the R language with TiSpark. |
||
|
||
### Usage | ||
1. Download TiSparkR source code and build a binary package(run `R CMD build R` in TiSpark root directory). Install it to your local R library(e.g. via `R CMD INSTALL TiSparkR_1.0.0.tar.gz`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
2. Build or download TiSpark dependency jar `tispark-core-1.0-RC1-jar-with-dependencies.jar` [here](https://github.com/pingcap/tispark). | ||
3. `cd` to your Spark home directory, and run | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
``` | ||
./bin/sparkR --jars /where-ever-it-is/tispark-core-${version}-jar-with-dependencies.jar | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The indentation is not correct. Please indent the code block with four whitespaces, to improve the display effect. |
||
Note that you should replace the `TiSpark` jar path with your own. | ||
|
||
4. Use as below in your R console: | ||
```R | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the indentation too. |
||
# import tisparkR library | ||
> library(TiSparkR) | ||
# create a TiContext instance | ||
> ti <- createTiContext(spark) | ||
# Map TiContext to database:tpch_test | ||
> tidbMapDatabase(ti, "tpch_test") | ||
|
||
# Run a sql query | ||
> customers <- sql("select * from customer") | ||
# Print schema | ||
> printSchema(customers) | ||
root | ||
|-- c_custkey: long (nullable = true) | ||
|-- c_name: string (nullable = true) | ||
|-- c_address: string (nullable = true) | ||
|-- c_nationkey: long (nullable = true) | ||
|-- c_phone: string (nullable = true) | ||
|-- c_acctbal: decimal(15,2) (nullable = true) | ||
|-- c_mktsegment: string (nullable = true) | ||
|-- c_comment: string (nullable = true) | ||
|
||
# Run a count query | ||
> count <- sql("select count(*) from customer") | ||
# Print count result | ||
> head(count) | ||
count(1) | ||
1 150 | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using following commands -> using the following commands (Sounds better)