ronantakizawa/codereview-bench huggingface dataset:
Repository: apache/arrow
File: cpp/src/arrow/util/thread_pool.h (C/C++)

Code before:
    auto maybe_gen = std::move(get_gen)(used_executor);
    if (!maybe_gen.ok()) {
      return MakeErrorIterator<T>(maybe_gen.status());
    }
    return MakeGeneratorIterator(*maybe_gen);
  } else {
    return SerialExecutor::IterateGenerator(std::move(get_gen));
  }
}

/// \brief Potentially iterate an async generator serially (if use_threads is false)
///   using the default CPU thread pool
/// \see IterateGenerator
///
/// If `use_threads` is true, the global CPU executor will be used.  Each call to
///   the iterator will simply wait until the next item is available.  Tasks may run in
///   the background between calls.
///
/// If `use_threads` is false, the calling thread only will be used.  Each call to
///   the iterator will use the calling thread to do enough work to generate one item.
///   Tasks will be left in a queue until the next call and no work will be done between
///   calls.
template <typename T>
Iterator<T> IterateSynchronously(
    FnOnce<Result<std::function<Future<T>()>>(Executor*)> get_gen, bool use_threads) {
  return IterateSynchronously(std::move(get_gen), use_threads, nullptr);
}

}  // namespace internal
}  // namespace arrow


Review comment (bug):
```suggestion
  return IterateSynchronously(std::move(get_gen), use_threads, NULLPTR);
```

Code after:
      return MakeErrorIterator<T>(maybe_gen.status());
    }
    return MakeGeneratorIterator(*maybe_gen);
  } else {
    return SerialExecutor::IterateGenerator(std::move(get_gen));
  }
}

/// \brief Potentially iterate an async generator serially (if use_threads is false)
///   using the default CPU thread pool
/// \see IterateGenerator
///
/// If `use_threads` is true, the global CPU executor will be used.  Each call to
///   the iterator will simply wait until the next item is available.  Tasks may run in
///   the background between calls.
///
/// If `use_threads` is false, the calling thread only will be used.  Each call to
///   the iterator will use the calling thread to do enough work to generate one item.
///   Tasks will be left in a queue until the next call and no work will be done between
///   calls.
template <typename T>
Iterator<T> IterateSynchronously(
    FnOnce<Result<std::function<Future<T>()>>(Executor*)> get_gen, bool use_threads) {
  return IterateSynchronously(std::move(get_gen), use_threads, NULLPTR);
}

}  // namespace internal
}  // namespace arrow
Repository: apache/arrow
File: cpp/src/arrow/compute/kernels/scalar_string_test.cc (C++)

Code before:
  uint8_t output[4];
  for (utf8proc_int32_t codepoint = 0x100; codepoint < 0x110000; codepoint++) {
    utf8proc_ssize_t encoded_nbytes = utf8proc_encode_char(codepoint, output);
    utf8proc_int32_t codepoint_upper = utf8proc_toupper(codepoint);
    utf8proc_ssize_t encoded_nbytes_upper = utf8proc_encode_char(codepoint_upper, output);
    // validate that upper casing will only lead to a byte length growth of max 3/2
    if (encoded_nbytes == 2) {
      EXPECT_LE(encoded_nbytes_upper, 3)
          << "Expected the upper case codepoint for a 2 byte encoded codepoint to be "
             "encoded in maximum 3 bytes, not "
          << encoded_nbytes_upper;
    }
    utf8proc_int32_t codepoint_lower = utf8proc_tolower(codepoint);
    utf8proc_ssize_t encoded_nbytes_lower = utf8proc_encode_char(codepoint_lower, output);
    // validate that lower casing will only lead to a byte length growth of max 3/2
    if (encoded_nbytes == 2) {
      EXPECT_LE(encoded_nbytes_lower, 3)
          << "Expected the lower case codepoint for a 2 byte encoded codepoint to be "
             "encoded in maximum 3 bytes, not "
          << encoded_nbytes_lower;
    }
  }
}
#endif

}  // namespace arrow::compute


Review comment (suggestion):
```suggestion
TEST(TestStringKernels, Utf8IsDigit) {
```

BTW, should we update existing (but empty) one instead of adding a new test?
https://github.com/apache/arrow/blob/19439118ce25620b9773fe3616aa1e4dab4fd098/cpp/src/arrow/compute/kernels/scalar_string_test.cc#L1386-L1391

Code after:
                   &options);
}

#ifdef ARROW_WITH_UTF8PROC
TEST(TestStringKernels, UnicodeLibraryAssumptions) {
  uint8_t output[4];
  for (utf8proc_int32_t codepoint = 0x100; codepoint < 0x110000; codepoint++) {
    utf8proc_ssize_t encoded_nbytes = utf8proc_encode_char(codepoint, output);
    utf8proc_int32_t codepoint_upper = utf8proc_toupper(codepoint);
    utf8proc_ssize_t encoded_nbytes_upper = utf8proc_encode_char(codepoint_upper, output);
    // validate that upper casing will only lead to a byte length growth of max 3/2
    if (encoded_nbytes == 2) {
      EXPECT_LE(encoded_nbytes_upper, 3)
          << "Expected the upper case codepoint for a 2 byte encoded codepoint to be "
             "encoded in maximum 3 bytes, not "
          << encoded_nbytes_upper;
    }
    utf8proc_int32_t codepoint_lower = utf8proc_tolower(codepoint);
    utf8proc_ssize_t encoded_nbytes_lower = utf8proc_encode_char(codepoint_lower, output);
    // validate that lower casing will only lead to a byte length growth of max 3/2
    if (encoded_nbytes == 2) {
      EXPECT_LE(encoded_nbytes_lower, 3)
          << "Expected the lower case codepoint for a 2 byte encoded codepoint to be "
             "encoded in maximum 3 bytes, not "
          << encoded_nbytes_lower;
    }
  }
}
#endif

}  // namespace arrow::compute
Repository: apache/arrow
File: r/R/filesystem.R (R)

Code before:
#' bucket <- gs_bucket("voltrondata-labs-datasets")
#' @export
gs_bucket <- function(bucket, ...) {
  assert_that(is.string(bucket))
  args <- list2(...)

  fs <- exec(GcsFileSystem$create, !!!args)

  SubTreeFileSystem$create(bucket, fs)
}

#' @usage NULL
#' @format NULL
#' @rdname FileSystem
#' @export
GcsFileSystem <- R6Class("GcsFileSystem",
  inherit = FileSystem,
  active = list(
    options = function() {
      out <- fs___GcsFileSystem__options(self)

      # Convert from nanoseconds to POSIXct w/ UTC tz
      if ("expiration" %in% names(out)) {
        out$expiration <- as.POSIXct(
          out$expiration / 1000000000,
          origin = "1970-01-01", tz = "UTC"
        )
      }

      out
    }
  )
)
GcsFileSystem$create <- function(anonymous = FALSE, retry_limit_seconds = 15, ...) {
  # The default retry limit in C++ is 15 minutes, but that is experienced as
  # hanging in an interactive context, so default is set here to 15 seconds.
  options <- list(...)

  # Validate options
  if (isTRUE(anonymous)) {
    invalid_args <- intersect(
      c("access_token", "expiration", "json_credentials"),
      names(options)
    )
    if (length(invalid_args)) {
      stop(
        "Cannot specify ",
        oxford_paste(invalid_args),
        " when anonymous = TRUE",
        call. = FALSE
      )

Review comment (suggestion):
I'm surprised that this wasn't produced: This is what it should be given linting definitions

```suggestion
          out$expiration / 1000000000,
          origin = "1970-01-01", 
          tz = "UTC"
```

Code after:
#' bucket <- gs_bucket("voltrondata-labs-datasets")
#' @export
gs_bucket <- function(bucket, ...) {
  assert_that(is.string(bucket))
  args <- list2(...)

  fs <- exec(GcsFileSystem$create, !!!args)

  SubTreeFileSystem$create(bucket, fs)
}

#' @usage NULL
#' @format NULL
#' @rdname FileSystem
#' @export
GcsFileSystem <- R6Class("GcsFileSystem",
  inherit = FileSystem,
  active = list(
    options = function() {
      out <- fs___GcsFileSystem__options(self)

      # Convert from nanoseconds to POSIXct w/ UTC tz
      if ("expiration" %in% names(out)) {
        out$expiration <- as.POSIXct(
          out$expiration / 1000000000,
          origin = "1970-01-01",
          tz = "UTC"
        )
      }

      out
    }
  )
)
GcsFileSystem$create <- function(anonymous = FALSE, retry_limit_seconds = 15, ...) {
  # The default retry limit in C++ is 15 minutes, but that is experienced as
  # hanging in an interactive context, so default is set here to 15 seconds.
  options <- list(...)

  # Validate options
  if (isTRUE(anonymous)) {
    invalid_args <- intersect(
      c("access_token", "expiration", "json_credentials"),
      names(options)
    )
    if (length(invalid_args)) {
      stop(
        "Cannot specify ",
        oxford_paste(invalid_args),
        " when anonymous = TRUE",
        call. = FALSE
Repository: apache/arrow
File: cpp/src/arrow/acero/util_test.cc (C++)

Code before:
  queue.Push(6);
  queue.Push(7);
  queue.Push(8);
  ASSERT_FALSE(dummy_node.paused);
  ASSERT_FALSE(dummy_node.stopped);
  queue.Push(9);
  ASSERT_TRUE(dummy_node.paused);
  ASSERT_FALSE(dummy_node.stopped);
  ASSERT_EQ(queue.TryPop(), std::make_optional(6));
  ASSERT_TRUE(dummy_node.paused);
  ASSERT_FALSE(dummy_node.stopped);
  ASSERT_EQ(queue.TryPop(), std::make_optional(7));
  ASSERT_FALSE(dummy_node.paused);
  ASSERT_FALSE(dummy_node.stopped);
  queue.Push(10);
  ASSERT_FALSE(dummy_node.paused);
  ASSERT_FALSE(dummy_node.stopped);
  queue.Push(11);
  ASSERT_TRUE(dummy_node.paused);
  ASSERT_FALSE(dummy_node.stopped);
  ASSERT_OK(queue.ForceShutdown());
  ASSERT_FALSE(dummy_node.paused);
  ASSERT_TRUE(dummy_node.stopped);
}

}  // namespace acero
}  // namespace arrow


Review comment (suggestion):
```suggestion
  ASSERT_OK_AND_ASSIGN(auto handler, BackpressureHandler::Make(/*low_threshold=*/2, /*high_threshold=*/4, std::move(ctrl)));
```

Code after:
  queue.Push(8);
  ASSERT_FALSE(dummy_node.paused);
  ASSERT_FALSE(dummy_node.stopped);
  queue.Push(9);
  ASSERT_TRUE(dummy_node.paused);
  ASSERT_FALSE(dummy_node.stopped);
  ASSERT_EQ(queue.TryPop(), std::make_optional(6));
  ASSERT_TRUE(dummy_node.paused);
  ASSERT_FALSE(dummy_node.stopped);
  ASSERT_EQ(queue.TryPop(), std::make_optional(7));
  ASSERT_FALSE(dummy_node.paused);
  ASSERT_FALSE(dummy_node.stopped);
  queue.Push(10);
  ASSERT_FALSE(dummy_node.paused);
  ASSERT_FALSE(dummy_node.stopped);
  queue.Push(11);
  ASSERT_TRUE(dummy_node.paused);
  ASSERT_FALSE(dummy_node.stopped);
  queue.ForceShutdown();
  ASSERT_FALSE(dummy_node.paused);
}

TEST(BackpressureConcurrentQueue, BackpressureTestStayUnpaused) {
  BackpressureTestExecNode dummy_node;
  auto ctrl = std::make_unique<TestBackpressureControl>(&dummy_node);
  ASSERT_OK_AND_ASSIGN(
      auto handler, BackpressureHandler::Make(/*low_threshold=*/2, /*high_threshold=*/4,
                                              std::move(ctrl)));
  BackpressureConcurrentQueue<int> queue(std::move(handler));

  queue.Push(6);
  queue.Push(7);
  queue.Push(8);
  ASSERT_FALSE(dummy_node.paused);
  ASSERT_FALSE(dummy_node.stopped);
  queue.ForceShutdown();
  for (int i = 0; i < 10; ++i) {
    queue.Push(i);
  }
  ASSERT_FALSE(dummy_node.paused);
}

}  // namespace acero
}  // namespace arrow
Repository: apache/arrow
File: cpp/src/arrow/c/bridge_test.cc (C++)

Code before:
  c_struct_.format = "+r";
  c_struct_.name = "";
  c_struct_.n_children = 2;
  c_struct_.children = children;
  CheckImportError();
}

TEST_F(TestSchemaImport, DictionaryError) {
  // Bad index type
  FillPrimitive(AddChild(), "c");
  FillPrimitive("u");
  FillDictionary();
  CheckImportError();

  // Nested dictionary
  FillPrimitive(AddChild(), "c");
  FillPrimitive(AddChild(), "u");
  FillDictionary(LastChild());
  FillPrimitive("u");
  FillDictionary();
  CheckImportError();
}

TEST_F(TestSchemaImport, ExtensionError) {
  ExtensionTypeGuard guard(uuid());

  // Storage type doesn't match
  FillPrimitive("w:15");
  c_struct_.metadata = kEncodedUuidMetadata.c_str();
  CheckImportError();

  // Invalid serialization
  std::string bogus_metadata = kEncodedUuidMetadata;
  bogus_metadata[bogus_metadata.size() - 5] += 1;
  FillPrimitive("w:16");
  c_struct_.metadata = bogus_metadata.c_str();
  CheckImportError();
}

TEST_F(TestSchemaImport, RecursionError) {
  FillPrimitive(AddChild(), "c", "unused");
  auto c = AddChild();
  FillStructLike(c, "+s", 1, "child");
  FillStructLike("+s", 1, "parent");
  c->children[0] = &c_struct_;
  CheckImportError();
}

TEST_F(TestSchemaImport, ImportField) {
  FillPrimitive("c", "thing", kDefaultFlags);
  CheckImport(field("thing", int8()));

Review comment (suggestion):
```suggestion
    // Decimal precision out of bounds
    FillPrimitive("d:0,10");
```

Code after:
  c_struct_.format = "+r";
  c_struct_.name = "";
  c_struct_.n_children = 2;
  c_struct_.children = children;
  CheckImportError();
}

TEST_F(TestSchemaImport, DictionaryError) {
  // Bad index type
  FillPrimitive(AddChild(), "c");
  FillPrimitive("u");
  FillDictionary();
  CheckImportError();

  // Nested dictionary
  FillPrimitive(AddChild(), "c");
  FillPrimitive(AddChild(), "u");
  FillDictionary(LastChild());
  FillPrimitive("u");
  FillDictionary();
  CheckImportError();
}

TEST_F(TestSchemaImport, DecimalError) {
  // Decimal precision out of bounds
  FillPrimitive("d:0,10");
  CheckImportError();
  FillPrimitive("d:39,10");
  CheckImportError();

  FillPrimitive("d:0,4,32");
  CheckImportError();
  FillPrimitive("d:10,4,32");
  CheckImportError();

  FillPrimitive("d:0,4,64");
  CheckImportError();
  FillPrimitive("d:19,4,64");
  CheckImportError();

  FillPrimitive("d:0,10,128");
  CheckImportError();
  FillPrimitive("d:39,10,128");
  CheckImportError();

  FillPrimitive("d:0,4,256");
  CheckImportError();
  FillPrimitive("d:77,4,256");
  CheckImportError();
}
Repository: apache/arrow
File: python/pyarrow/tests/test_scalars.py (Python)

Code before:
    Check we can call `MapScalar.as_py` with custom field names

    See https://github.com/apache/arrow/issues/36809
    """
    assert pa.scalar(
        [("foo", "bar")],
        pa.map_(
            pa.string(),
            pa.string()
        ),
    ).as_py() == [("foo", "bar")]

    assert pa.scalar(
        [("foo", "bar")],
        pa.map_(
            pa.field("custom_key", pa.string(), nullable=False),
            pa.field("custom_value", pa.string()),
        ),
    ).as_py() == [("foo", "bar")]


def test_nested_map_types_with_maps_as_pydicts():
    ty = pa.struct(
        [
            pa.field('x', pa.map_(pa.string(), pa.map_(pa.string(), pa.int8()))),
            pa.field(
                'y', pa.list_(pa.map_(pa.string(), pa.map_(pa.string(), pa.int8())))
            ),
        ]
    )

    v = {'x': {'a': {'1': 1}}, 'y': [{'b': {'2': 2}}, {'c': {'3': 3}}]}
    s = pa.scalar(v, type=ty)

    assert s.as_py(maps_as_pydicts="strict") == v


Review comment (suggestion):
could we have both test example validations? We would validate the previous functionality is still working as it was before maintaining the old test.

Code after:
    Check we can call `MapScalar.as_py` with custom field names

    See https://github.com/apache/arrow/issues/36809
    """
    assert pa.scalar(
        [("foo", "bar")],
        pa.map_(
            pa.string(),
            pa.string()
        ),
    ).as_py() == [("foo", "bar")]

    assert pa.scalar(
        [("foo", "bar")],
        pa.map_(
            pa.field("custom_key", pa.string(), nullable=False),
            pa.field("custom_value", pa.string()),
        ),
    ).as_py() == [("foo", "bar")]


def test_map_types_with_maps_as_pydicts():
    ty = pa.struct([
        pa.field('x', pa.map_(pa.string(), pa.int8())),
        pa.field('y', pa.list_(pa.map_(pa.string(), pa.int8()))),
    ])

    v = {'x': {'a': 1}, 'y': [{'b': 2}, {'c': 3}]}
    s = pa.scalar(v, type=ty)

    assert s.as_py(maps_as_pydicts="strict") == v


def test_nested_map_types_with_maps_as_pydicts():
    ty = pa.struct(
        [
            pa.field('x', pa.map_(pa.string(), pa.map_(pa.string(), pa.int8()))),
            pa.field(
                'y', pa.list_(pa.map_(pa.string(), pa.map_(pa.string(), pa.int8())))
            ),
        ]
    )

    v = {'x': {'a': {'1': 1}}, 'y': [{'b': {'2': 2}}, {'c': {'3': 3}}]}
    s = pa.scalar(v, type=ty)

    assert s.as_py(maps_as_pydicts="strict") == v


def test_map_scalar_with_empty_values():
    map_type = pa.struct(
Repository: apache/arrow
File: cpp/src/arrow/flight/sql/odbc/odbc_api_internal.h (C/C++)

Code before:
// 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
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

#pragma once

#ifdef _WIN32
#  include <windows.h>
#endif

#include <sql.h>
#include <sqltypes.h>
#include <sqlucode.h>

//  \file odbc_api_internal.h
//
//  Define internal ODBC API function headers.
namespace arrow::flight::sql::odbc {
SQLRETURN SQLAllocHandle(SQLSMALLINT type, SQLHANDLE parent, SQLHANDLE* result);
}  // namespace arrow::flight::sql::odbc


Review comment (refactor):
Should we use `#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/platform.h"` instead? It seems that `platform.h` defines some macros before including `windows.h`.

Code after:
// 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
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

#pragma once

#include "arrow/flight/sql/odbc/odbcabstraction/include/odbcabstraction/platform.h"

#include <sql.h>
#include <sqltypes.h>
#include <sqlucode.h>

//  \file odbc_api_internal.h
//
//  Define internal ODBC API function headers.
namespace arrow::flight::sql::odbc {
SQLRETURN SQLAllocHandle(SQLSMALLINT type, SQLHANDLE parent, SQLHANDLE* result);
}  // namespace arrow::flight::sql::odbc
Repository: apache/arrow
File: cpp/src/arrow/csv/options.h (C/C++)

Code before:
struct ARROW_EXPORT WriteOptions {
  /// Whether to write an initial header line with column names
  bool include_header = true;

  /// \brief Maximum number of rows processed at a time
  ///
  /// The CSV writer converts and writes data in batches of N rows.
  /// This number can impact performance.
  int32_t batch_size = 1024;

  /// Field delimiter
  char delimiter = ',';

  /// \brief The string to write for null values. Quotes are not allowed in this string.
  std::string null_string;

  /// \brief IO context for writing.
  io::IOContext io_context;

  /// \brief The end of line character to use for ending rows
  std::string eol = "\n";

  /// \brief Quoting style
  QuotingStyle quoting_style = QuotingStyle::Needed;

  /// \brief Quoting style of header
  QuotingStyle quoting_header = QuotingStyle::Needed;

  /// Create write options with default values
  static WriteOptions Defaults();

  /// \brief Test that all set options are valid
  Status Validate() const;
};

}  // namespace csv
}  // namespace arrow


Review comment (suggestion):
```suggestion
  /// \brief Quoting style of header
  ///
  /// Note that `QuotingStyle::Needed` and `QuotingStyle::AllValid` have the same
  /// effect of quoting all column names.
```

Code after:
struct ARROW_EXPORT WriteOptions {
  /// Whether to write an initial header line with column names
  bool include_header = true;

  /// \brief Maximum number of rows processed at a time
  ///
  /// The CSV writer converts and writes data in batches of N rows.
  /// This number can impact performance.
  int32_t batch_size = 1024;

  /// Field delimiter
  char delimiter = ',';

  /// \brief The string to write for null values. Quotes are not allowed in this string.
  std::string null_string;

  /// \brief IO context for writing.
  io::IOContext io_context;

  /// \brief The end of line character to use for ending rows
  std::string eol = "\n";

  /// \brief Quoting style
  QuotingStyle quoting_style = QuotingStyle::Needed;

  /// \brief Quoting style of header
  ///
  /// Note that `QuotingStyle::Needed` and `QuotingStyle::AllValid` have the same
  /// effect of quoting all column names.
  QuotingStyle quoting_header = QuotingStyle::Needed;

  /// Create write options with default values
  static WriteOptions Defaults();

  /// \brief Test that all set options are valid
  Status Validate() const;
};

}  // namespace csv
}  // namespace arrow
Repository: apache/arrow
File: ci/scripts/install_azurite.sh (Shell)

Code before:
# 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
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

set -e

node_version="$(node --version)"
echo "Node.js version = ${node_version}"

case "${node_version}" in
  v12.*)
    echo "Node.js is too old. We can't install Azurite."
    exit
    ;;
esac

azurite_version=latest
case "$(uname)" in
  Darwin)
    npm install -g azurite@${azurite_version}
    which azurite
    ;;
  MINGW*)
    choco install nodejs.install
    npm install -g azurite@${azurite_version}
    ;;
  Linux)
    npm install -g azurite@${azurite_version}
    which azurite
    ;;
esac
echo "Azurite version = $(azurite --version)"


Review comment (bug):
Perhaps return an error here?
```suggestion
    exit 1
```

Code after:
# 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
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

set -e

node_version="$(node --version)"
echo "Node.js version = ${node_version}"

azurite_version=latest
case "$(uname)" in
  Darwin)
    npm install -g azurite@${azurite_version}
    which azurite
    ;;
  MINGW*)
    choco install nodejs.install
    npm install -g azurite@${azurite_version}
    ;;
  Linux)
    npm install -g azurite@${azurite_version}
    which azurite
    ;;
esac
echo "Azurite version = $(azurite --version)"