Skip to content

Instantly share code, notes, and snippets.

View RaviTella's full-sized avatar

Ravi Tella RaviTella

  • Microsoft
  • Atlanta, GA
View GitHub Profile
import org.apache.spark.sql.{SaveMode, SparkSession}
object HelloCosmos {
val cosmosEndpoint = ""
val cosmosMasterKey = ""
val cosmosDatabaseName = "bstore"
val cosmosContainerName = "books"
azure.cosmos.uri=https://some-cosmossql-demo.documents.azure.com:443/
azure.cosmos.key=APEDwfem16N7K74Il5Y5SSSSOMby7KAIfrLnzKOV0JMMoaedg0IhHepvmLOi7HnG5mHIRCyqomSTj6oa3urlOg==
azure.cosmos.database=store
@Component
public class CustomerLoader {
private CustomerRepository customerRepository;
@Autowired
CustomerLoader(CustomerRepository customerRepository){
this.customerRepository=customerRepository;
}
@PostConstruct
@RestController
public class CustomerController {
private CustomerRepository customerRepository;
@Autowired
CustomerController(CustomerRepository customerRepository) {
this.customerRepository = customerRepository;
}
@GetMapping("/customers")
@Repository
public interface CustomerRepository extends CosmosRepository<Customer,String> {}
public class Customer {
@Id
@PartitionKey
String id;
String firstName;
String lastName;
String emailAddress;
String zipcode;
public Customer(String id, String firstName, String lastName, String emailAddress, String zipcode) {
@RaviTella
RaviTella / customers.json
Created February 10, 2022 01:32
Customer service response
[
{
"id": "1",
"firstName": "Ravi",
"lastName": "Tella",
"emailAddress": "ravi@email.com",
"zipcode": "33333"
},
{
"id": "2",
@RaviTella
RaviTella / CosmosSQLPatch.java
Last active November 30, 2021 18:00
Cosmos SQL Patch API sample code
//Patch using a json string with JsonNode (JAckson)
private static void pathUpdate1() throws JsonProcessingException {
String json = "{\"City\":\"Atlanta\",\"State\": \"GA\",\"Country\":\"USA\"}";
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(json);
CosmosPatchOperations cosmosPatchOperations2 = CosmosPatchOperations.create();
cosmosPatchOperations2.add("/address1", jsonNode);
CosmosPatchItemRequestOptions options2 = new CosmosPatchItemRequestOptions();
cosmosDB.getContainer().patchItem("6", new PartitionKey("Databases"),
cosmosPatchOperations2, options2, Book.class).block();
package com.example.demo;
import com.microsoft.azure.documentdb.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RaviTella
RaviTella / SparkStreamingToPowerBI.scala
Last active May 6, 2020 03:50
Databricks Spark Streaming to Power BI Streaming Datasets
def sendToPBI(rowAsJson: String ): Unit = {
val post = new HttpPost("")
post.addHeader(HttpHeaders.CONTENT_TYPE, "application/json")
post.setEntity(new StringEntity(rowAsJson))
val response = (HttpClientBuilder.create().build()).execute(post)
}
import org.apache.spark.sql._
castedTelemetryData