|
| 1 | +--- |
| 2 | +apiVersion: spark.stackable.tech/v1alpha1 |
| 3 | +kind: SparkApplication |
| 4 | +metadata: |
| 5 | + name: test-spark-hbase-connector |
| 6 | +spec: |
| 7 | +{% if lookup('env', 'VECTOR_AGGREGATOR') %} |
| 8 | + vectorAggregatorConfigMapName: vector-aggregator-discovery |
| 9 | +{% endif %} |
| 10 | + sparkImage: |
| 11 | +{% if test_scenario['values']['spark'].find(",") > 0 %} |
| 12 | + custom: "{{ test_scenario['values']['spark'].split(',')[1] }}" |
| 13 | + productVersion: "{{ test_scenario['values']['spark'].split(',')[0] }}" |
| 14 | +{% else %} |
| 15 | + productVersion: "{{ test_scenario['values']['spark'] }}" |
| 16 | +{% endif %} |
| 17 | + # pullPolicy: IfNotPresent |
| 18 | + pullPolicy: Always |
| 19 | + mode: cluster |
| 20 | + mainApplicationFile: local:///stackable/spark/jobs/test-hbase.py |
| 21 | + sparkConf: |
| 22 | + spark.driver.extraClassPath: /stackable/spark/config |
| 23 | + spark.executor.extraClassPath: /stackable/spark/config |
| 24 | + driver: |
| 25 | + config: |
| 26 | + logging: |
| 27 | + enableVectorAgent: {{ lookup('env', 'VECTOR_AGGREGATOR') | length > 0 }} |
| 28 | + volumeMounts: |
| 29 | + - name: script |
| 30 | + mountPath: /stackable/spark/jobs |
| 31 | + - name: hbase-config |
| 32 | + mountPath: /stackable/spark/config/hbase-site.xml |
| 33 | + subPath: hbase-site.xml |
| 34 | + - name: hdfs-config |
| 35 | + mountPath: /stackable/spark/config/hdfs-site.xml |
| 36 | + subPath: hdfs-site.xml |
| 37 | + - name: hdfs-config |
| 38 | + mountPath: /stackable/spark/config/core-site.xml |
| 39 | + subPath: core-site.xml |
| 40 | + executor: |
| 41 | + replicas: 1 |
| 42 | + config: |
| 43 | + logging: |
| 44 | + enableVectorAgent: {{ lookup('env', 'VECTOR_AGGREGATOR') | length > 0 }} |
| 45 | + volumeMounts: |
| 46 | + - name: script |
| 47 | + mountPath: /stackable/spark/jobs |
| 48 | + - name: hbase-config |
| 49 | + mountPath: /stackable/spark/config/hbase-site.xml |
| 50 | + subPath: hbase-site.xml |
| 51 | + - name: hdfs-config |
| 52 | + mountPath: /stackable/spark/config/hdfs-site.xml |
| 53 | + subPath: hdfs-site.xml |
| 54 | + - name: hdfs-config |
| 55 | + mountPath: /stackable/spark/config/core-site.xml |
| 56 | + subPath: core-site.xml |
| 57 | + volumes: |
| 58 | + - name: script |
| 59 | + configMap: |
| 60 | + name: test-hbase |
| 61 | + - name: hbase-config |
| 62 | + configMap: |
| 63 | + name: test-hbase |
| 64 | + - name: hdfs-config |
| 65 | + configMap: |
| 66 | + name: test-hdfs |
| 67 | +--- |
| 68 | +apiVersion: v1 |
| 69 | +kind: ConfigMap |
| 70 | +metadata: |
| 71 | + name: test-hbase |
| 72 | +data: |
| 73 | + test-hbase.py: | |
| 74 | + import os |
| 75 | + from pyspark.sql import SparkSession |
| 76 | + from pyspark.sql.types import * |
| 77 | + |
| 78 | + spark = SparkSession.builder.appName("test-hbase").getOrCreate() |
| 79 | + |
| 80 | + df = spark.createDataFrame( |
| 81 | + [("row1", "Hello, Stackable!")], |
| 82 | + "key: string, value: string" |
| 83 | + ) |
| 84 | + |
| 85 | + spark._jvm.org.apache.hadoop.hbase.spark.HBaseContext( |
| 86 | + spark._jsc.sc(), |
| 87 | + spark._jvm.org.apache.hadoop.hbase.HBaseConfiguration.create(), |
| 88 | + None, |
| 89 | + ) |
| 90 | + |
| 91 | + catalog = '{\ |
| 92 | + "table":{"namespace":"default","name":"test-hbase"},\ |
| 93 | + "rowkey":"key",\ |
| 94 | + "columns":{\ |
| 95 | + "key":{"cf":"rowkey","col":"key","type":"string"},\ |
| 96 | + "value":{"cf":"cf1","col":"value","type":"string"}\ |
| 97 | + }}' |
| 98 | + |
| 99 | + df\ |
| 100 | + .write\ |
| 101 | + .format("org.apache.hadoop.hbase.spark")\ |
| 102 | + .option('catalog', catalog)\ |
| 103 | + .option('newtable', '5')\ |
| 104 | + .save() |
0 commit comments