Skip to content

Instantly share code, notes, and snippets.

@AzimUddin
AzimUddin / Student.cs
Created September 3, 2015 15:18
Student - a sample document
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.Documents;
namespace DocumentDBPerfScaleTest
{
public class Student
@AzimUddin
AzimUddin / QueryMasterResources.cs
Last active September 2, 2015 21:29
An example of querying Master resources in Azure DocumentDB
// Check if database exists, if not create it
Database database = client.CreateDatabaseQuery().Where(db => db.Id == id).ToArray().FirstOrDefault();
if (database == null)
{
database = await client.CreateDatabaseAsync(new Database { Id = id });
}
// Get collection
StudentsCollection = client.CreateDocumentCollectionQuery(database.SelfLink).Where(c => c.Id == collectionId).ToArray().FirstOrDefault();
@AzimUddin
AzimUddin / MeasureRequestCharge.cs
Last active September 3, 2015 15:02
An example of measuring Request Charge for an insert Operation for Azure DocumentDB
private async Task InsertDocumentAsync(Student student, bool showDebugInfo)
{
ResourceResponse<Document> response = await client.CreateDocumentAsync(colSelfLink, student);
Console.WriteLine("{0}\tInsert Operation, # of RUs: {1}", DateTime.UtcNow, response.RequestCharge);
}
@AzimUddin
AzimUddin / ExecuteWithRetryNode.js
Last active August 30, 2015 17:52
Azure DocumentDB node.js example of executing a method with retry to handle RequestRateTooLargeException or HTTP 429 errors
var queryIterator = documentClient.queryDocuments(collection._self, query);
executeNextWithRetry(yourCallback);
function executeNextWithRetry(callback) {
queryIterator.executeNext(function(err, results, responseHeaders) {
if(err && err.code === 429 && responseHeaders['x-ms-retry-after-ms']) {
console.log("Retrying after " + responseHeaders['x-ms-retry-after-ms']);
setTimeout(function() {
@AzimUddin
AzimUddin / BulkImport.js
Last active September 18, 2015 23:10
An example of DocumentDB performance scale test with .Net SDK
/* Copied from: https://github.com/Azure/azure-documentdb-net/blob/master/samples/code-samples/ServerSideScripts/JS/BulkImport.js
*/
function bulkImport(docs) {
var collection = getContext().getCollection();
var collectionLink = collection.getSelfLink();
// The count of imported docs, also used as current doc index.
var count = 0;
@AzimUddin
AzimUddin / ExecuteWithRetryExample.cs
Last active January 18, 2016 10:18
Azure DocumentDB .Net SDK example of executing an Async method with retry to handle RequestRateTooLargeException or HTTP 429 errors
/// <summary>
/// Execute the function with retries on throttle
/// </summary>
/// <typeparam name="V"></typeparam>
/// <param name="client"></param>
/// <param name="function"></param>
/// <returns></returns>
private static async Task<V> ExecuteWithRetries<V>(DocumentClient client, Func<Task<V>> function)
{
TimeSpan sleepTime = TimeSpan.Zero;
@AzimUddin
AzimUddin / JDBC_Hive_POM_XML.xml
Last active August 29, 2015 14:22
POM.xml for using JDBC to access HiveServer2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.css</groupId>
<artifactId>HiveJdbcTest</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>HiveJdbcTest</name>
<url>http://maven.apache.org</url>
<dependencies>
@AzimUddin
AzimUddin / MyHiveJdbcTest.java
Last active November 6, 2018 14:32
Java sample using JDBC to connect to Hiveserver2 on Azure HDInsight
package com.microsoft.css;
/**
* Created by muddin on 6/4/2015.
*/
import java.sql.*;
public class MyHiveJdbcTest {
public static void main(String[] args) throws SQLException {
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.css</groupId>
<artifactId>HBaseJavaApiTest</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>HBaseJavaApiTest</name>
<url>http://maven.apache.org</url>
<dependencies>
@AzimUddin
AzimUddin / HBase-JAVA-API-hbase-site.xml
Last active August 29, 2015 14:08
sample hbase-site.xml for using HBase JAVA API
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
/**
* Copyright 2010 The Apache Software Foundation
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file