Exemplo n.º 1
0
        public IDStreamProxy KafkaStream(Dictionary <string, int> topics, Dictionary <string, string> kafkaParams, StorageLevelType storageLevelType)
        {
            JvmObjectReference jtopics      = JvmBridgeUtils.GetJavaMap <string, int>(topics);
            JvmObjectReference jkafkaParams = JvmBridgeUtils.GetJavaMap <string, string>(kafkaParams);
            JvmObjectReference jlevel       = SparkContextIpcProxy.GetJavaStorageLevel(storageLevelType);
            // KafkaUtilsPythonHelper: external/kafka/src/main/scala/org/apache/spark/streaming/kafka/KafkaUtils.scala
            JvmObjectReference jhelper = SparkCLRIpcProxy.JvmBridge.CallConstructor("org.apache.spark.streaming.kafka.KafkaUtilsPythonHelper", new object[] { });
            var jstream = new JvmObjectReference(SparkCLRIpcProxy.JvmBridge.CallNonStaticJavaMethod(jhelper, "createStream", new object[] { jvmJavaStreamingReference, jkafkaParams, jtopics, jlevel }).ToString());

            return(new DStreamIpcProxy(jstream));
        }
Exemplo n.º 2
0
        public IDStreamProxy DirectKafkaStream(List <string> topics, Dictionary <string, string> kafkaParams, Dictionary <string, long> fromOffsets)
        {
            JvmObjectReference jtopics      = JvmBridgeUtils.GetJavaSet <string>(topics);
            JvmObjectReference jkafkaParams = JvmBridgeUtils.GetJavaMap <string, string>(kafkaParams);

            var jTopicAndPartitions = fromOffsets.Select(x =>
                                                         new KeyValuePair <JvmObjectReference, long>
                                                         (
                                                             SparkCLRIpcProxy.JvmBridge.CallConstructor("kafka.common.TopicAndPartition", new object[] { x.Key.Split(':')[0], int.Parse(x.Key.Split(':')[1]) }),
                                                             x.Value
                                                         )
                                                         );

            JvmObjectReference jfromOffsets = JvmBridgeUtils.GetJavaMap <JvmObjectReference, long>(jTopicAndPartitions);
            // KafkaUtilsPythonHelper: external/kafka/src/main/scala/org/apache/spark/streaming/kafka/KafkaUtils.scala
            JvmObjectReference jhelper = SparkCLRIpcProxy.JvmBridge.CallConstructor("org.apache.spark.streaming.kafka.KafkaUtilsPythonHelper", new object[] { });
            var jstream = new JvmObjectReference(SparkCLRIpcProxy.JvmBridge.CallNonStaticJavaMethod(jhelper, "createDirectStreamWithoutMessageHandler", new object[] { jvmJavaStreamingReference, jkafkaParams, jtopics, jfromOffsets }).ToString());

            return(new DStreamIpcProxy(jstream));
        }
Exemplo n.º 3
0
        public IDStreamProxy DirectKafkaStreamWithRepartition(List <string> topics, IEnumerable <Tuple <string, string> > kafkaParams, IEnumerable <Tuple <string, long> > fromOffsets, int numPartitions, byte[] readFunc, string serializationMode)
        {
            JvmObjectReference jtopics      = JvmBridgeUtils.GetJavaSet <string>(topics);
            JvmObjectReference jkafkaParams = JvmBridgeUtils.GetJavaMap <string, string>(kafkaParams);

            var jTopicAndPartitions = fromOffsets.Select(x =>
                                                         new Tuple <JvmObjectReference, long>
                                                         (
                                                             SparkCLRIpcProxy.JvmBridge.CallConstructor("kafka.common.TopicAndPartition", new object[] { x.Item1.Split(':')[0], int.Parse(x.Item1.Split(':')[1]) }),
                                                             x.Item2
                                                         )
                                                         );

            JvmObjectReference jfromOffsets = JvmBridgeUtils.GetJavaMap <JvmObjectReference, long>(jTopicAndPartitions);
            // SparkCLR\scala\src\main\org\apache\spark\streaming\api\kafka\KafkaUtilsCSharpHelper.scala
            JvmObjectReference jhelper = SparkCLRIpcProxy.JvmBridge.CallConstructor("org.apache.spark.streaming.kafka.KafkaUtilsCSharpHelper", new object[] { });
            var jstream = new JvmObjectReference(SparkCLRIpcProxy.JvmBridge.CallNonStaticJavaMethod(jhelper, "createDirectStreamWithoutMessageHandler",
                                                                                                    new object[] { jvmJavaStreamingReference, jkafkaParams, jtopics, jfromOffsets, (int)numPartitions, readFunc, serializationMode }).ToString());

            return(new DStreamIpcProxy(jstream));
        }
Exemplo n.º 4
0
        public void SaveAsHadoopFile(string path, string outputFormatClass, string keyClass, string valueClass, IEnumerable <Tuple <string, string> > conf, string compressionCodecClass)
        {
            var jconf = JvmBridgeUtils.GetJavaMap <string, string>(conf);

            SparkCLRIpcProxy.JvmBridge.CallStaticJavaMethod("org.apache.spark.api.python.PythonRDD", "saveAsHadoopFile", new object[] { jvmRddReference, false, path, outputFormatClass, keyClass, valueClass, null, null, jconf, compressionCodecClass });
        }
Exemplo n.º 5
0
        public void SaveAsHadoopDataset(IEnumerable <Tuple <string, string> > conf)
        {
            var jconf = JvmBridgeUtils.GetJavaMap <string, string>(conf);

            SparkCLRIpcProxy.JvmBridge.CallStaticJavaMethod("org.apache.spark.api.python.PythonRDD", "saveAsHadoopDataset", new object[] { jvmRddReference, false, jconf, null, null, false });
        }
Exemplo n.º 6
0
        public IRDDProxy SampleByKey(bool withReplacement, IEnumerable <Tuple <string, double> > fractions, long seed)
        {
            var jfractions = JvmBridgeUtils.GetJavaMap(fractions) as JvmObjectReference;

            return(new RDDIpcProxy(new JvmObjectReference((string)SparkCLRIpcProxy.JvmBridge.CallNonStaticJavaMethod(jvmRddReference, "sampleByKey", new object[] { withReplacement, jfractions, seed }))));
        }