, but here read the local TXT file, configure sparkconf () as follows:
Explain: Local[n]: Local mode, using N threads.
The following program uses count () to count the number of rows
Statistic frequency and sort by word frequency:
Map () and Flatmap () difference:
The above program can be flatmap by the map and flatten synthesis, but also can be found that Fla
Unlike many proprietary large data-processing platforms, Spark is built on the unified abstraction of RDD, making it possible to deal with different large data-processing scenarios in a fundamentally consistent manner, including mapreduce,streaming,sql,machine learning and graph. This is what Matei Zaharia called "Designing a Generic programming abstraction (Unified programming Abstraction)." This is the place where the spark sparks are fascinating.
To understand spark, you need to understand RD
Collection Dependencies (): Dependency collection of current Rdd iterator (split, context): Functions Partitioner (): Partitioning methods such as Hashpartitioner and Rangepartitioner preferredlocations (split) for each partition calculation or read operation: Access the fastest node of a partition
All RDD inherit the abstract class Rdd. Several common operations: sc#textfile: Generate Hadooprdd, which represents an RDD sc#parallelize that can read data from HDFs: Generate Parallelcollectionrdd
x*2. It can also be seen here that functional programming focuses on what to do (x*2), rather than on how to do it (using the loop control structure). The programmer does not care at all whether the elements in the list are calculated from the front to the back, from the back to the front, in sequential or parallel computations, such as Scala's parallel collection (Parallel collection).Using the method of the collection class, you can make it easier for some processing, such as the above-mentio
publicMapreturnarticles.stream().collect(Collectors.groupingBy(Article::getAuthor));}
Very good! Using the Groupingby operation and the Getauthor method, we get a cleaner, more readable code.Now we look at all the different tags in the collection.Let's start with the example of using loops.
12345678910
public set set new Code class= "Java Plain" >hashsetNBSP;NBSP;NBSP;NBSP; for (article article:articles) { result.addall (Article.gettags ()); NBSP
correct.
2.fromIterable method, if I have a list in my hand now, I'm going to shoot it through flowable, and I'll teach you.
list
Print results:
04-20 16:38:16.404 24914-24914/org.jan.rxandroiddemo i/simplefunc1activity:---from->10
04-20 16:38:16.404 24914-24914/org.jan.rxandroiddemo i/simplefunc1activity:---from->15
04-20 16:38:16.404 24914-24914/ Org.jan.rxandroiddemo i/simplefunc1activity:---from->20
04-20 16:38:16.404 24914-24914/ Org.jan.rxandroiddemo i/simplefunc1activity:---from
data operation is assigned to the buffer object, and the result is executed: (A;;; b;; c;; D;; e;; f;;
g) c val buffer = new StringBuilder ();
data.addstring (Buffer, "(", ";;", "));
println (buffer);
The list and array convert the Val array =data println (Array.toarray) to each other;
println (array.tolist); The elements in the copy data object into the NewArray array, where copy to 3 is located after Val newarray = new Array[char] (a) Data.copytoarray (newarray,3
Transformations (conversion)
Transformation
Description
Map (func)
Each element in the original Rdd object is processed according to the incoming function, and after each new element is processed, an object is returned, which is assembled to get a new rdd, and the new Rdd and the old RDD elements are all one by one corresponding
Filter (func)
Filter each element in the RDD according to the function passed in, forming a new rdd with the elemen
Addcalladapterfactory (Rxjava2calladapterfactory.create ())
2, RxJava
We send the data by just way
Flatmap method is used for data format conversion method, the following parameters Userparam and observablesource
This case is actually the user to add the shopping cart, the first will be stored locally, and then found that if there is no network, then no way to submit to the server, you can only wait for the next time the networ
function. The input function also needs to enter two parameters: the cumulative value and the index of the current item. Fold indefinite order, foldleft from left to right.
Flatten: The nested structure is expanded.
Scala> list (list (1, 2), List (3, 4= List (1, 2, 3, 4)
FlatMap: A common combinator that combines the functions of map and flatten. Flatmap receives a function that can handl
Shorthand Argument NamesSwift automatically provides shorthand argument names to inline closures, which can is used to refer to the values of the Closure ' s arguments by the names,, $0 $1 $2 , and so on.If You use these shorthand argument names within your closure expression, you can omit the closure ' s argument list from it s definition, and the number and type of the shorthand argument names would be the inferred from the expected function type. inThe keyword can also be omitted, because the
parsed and installed.
The breakpoint download posture is enabled!
Breakpoint download
apiServiece
@GET@StreamingObservable
> download(@Header("Range") String range, @Url String url);
API
** DownLoadInfo ** s contains name, lenth,. url, and so on. It will not be pasted here. View the API directly
DownloadTypeThe records must include stats, mLastModify, downloded, savepath, etc.
public Observable
download(@NonNull final String url, @NonNull fina
; Public Static void Main(string[] args) {sparkconf conf =NewSparkconf (). Setmaster ("local[2]"). Setappname ("Wordcountonliebroadcast"); Javastreamingcontext JSC =NewJavastreamingcontext (conf, Durations.seconds (5));/** * If there is no action, the broadcast will not be sent out! * * Use broadcast broadcast blacklist to every executor! */Broadcastlist = Jsc.sc (). Broadcast (Arrays.aslist ("Hadoop","Mahout","Hive"));/** * Global Counter! Used to count the number of blacklisted
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.