<commit_before>/*
 * Copyright (c) 2012-2019 Snowflake Computing Inc. All rights reserved.
 */
package net.snowflake.client.core.arrow;

import net.snowflake.client.core.DataConversionContext;
import net.snowflake.client.core.IncidentUtil;
import net.snowflake.client.core.ResultUtil;
import net.snowflake.client.core.SFException;
import net.snowflake.client.jdbc.ErrorCode;
import net.snowflake.client.jdbc.SnowflakeType;
import org.apache.arrow.vector.IntVector;
import org.apache.arrow.vector.ValueVector;

import java.sql.Date;
import java.sql.Timestamp;
import java.util.TimeZone;

public class IntToDateConverter extends AbstractArrowVectorConverter
{
  private IntVector intVector;

  public IntToDateConverter(ValueVector fieldVector, int columnIndex, DataConversionContext context)
  {
    super(SnowflakeType.DATE.name(), fieldVector, columnIndex, context);
    this.intVector = (IntVector) fieldVector;
  }

  @Override
  public Date toDate(int index) throws SFException
  {
    if (isNull(index))
    {
      return null;
    }
    else
    {
      int val = intVector.getDataBuffer().getInt(index * IntVector.TYPE_WIDTH);
      // Note: use default time zone to match with current getDate() behavior
      return ArrowResultUtil.getDate(val, TimeZone.getDefault(), context.getSession());
    }
  }

  @Override
  public int toInt(int index)
  {
    if (isNull(index))
    {
      return 0;
    }
    else
    {
      int val = intVector.getDataBuffer().getInt(index * IntVector.TYPE_WIDTH);
      return val;
    }
  }

  @Override
  public Timestamp toTimestamp(int index, TimeZone tz) throws SFException
  {
    if (isNull(index))
    {
      return null;
    }
    else
    {
      return new Timestamp(toDate(index).getTime());
    }
  }

  @Override
  public String toString(int index) throws SFException
  {
    if (context.getDateFormatter() == null)
    {
      throw (SFException) IncidentUtil.generateIncidentV2WithException(
          context.getSession(),
          new SFException(ErrorCode.INTERNAL_ERROR,
                          "missing date formatter"),
          null,
          null);
    }
    return isNull(index) ? null :
           ResultUtil.getDateAsString(toDate(index), context.getDateFormatter());
  }

  @Override
  public Object toObject(int index) throws SFException
  {
    return isNull(index) ? null : toDate(index);
  }
}<commit_msg>SNOW-81290: Support DATE, TIME, TIMESTAMP data types in JDBC for arrow result format<commit_after>/*
 * Copyright (c) 2012-2019 Snowflake Computing Inc. All rights reserved.
 */
package net.snowflake.client.core.arrow;

import net.snowflake.client.core.DataConversionContext;
import net.snowflake.client.core.IncidentUtil;
import net.snowflake.client.core.ResultUtil;
import net.snowflake.client.core.SFException;
import net.snowflake.client.jdbc.ErrorCode;
import net.snowflake.client.jdbc.SnowflakeType;
import org.apache.arrow.vector.IntVector;
import org.apache.arrow.vector.ValueVector;

import java.sql.Date;
import java.sql.Timestamp;
import java.util.TimeZone;

public class IntToDateConverter extends AbstractArrowVectorConverter
{
  private IntVector intVector;

  public IntToDateConverter(ValueVector fieldVector, int columnIndex, DataConversionContext context)
  {
    super(SnowflakeType.DATE.name(), fieldVector, columnIndex, context);
    this.intVector = (IntVector) fieldVector;
  }

  @Override
  public Date toDate(int index) throws SFException
  {
    if (isNull(index))
    {
      return null;
    }
    else
    {
      int val = intVector.getDataBuffer().getInt(index * IntVector.TYPE_WIDTH);
      // Note: use default time zone to match with current getDate() behavior
      return ArrowResultUtil.getDate(val, TimeZone.getDefault(), context.getSession());
    }
  }

  @Override
  public int toInt(int index)
  {
    if (isNull(index))
    {
      return 0;
    }
    else
    {
      int val = intVector.getDataBuffer().getInt(index * IntVector.TYPE_WIDTH);
      return val;
    }
  }

  @Override
  public Timestamp toTimestamp(int index, TimeZone tz) throws SFException
  {
    Date date = toDate(index);
    if (date == null)
    {
      return null;
    }
    else
    {
      return new Timestamp(date.getTime());
    }
  }

  @Override
  public String toString(int index) throws SFException
  {
    if (context.getDateFormatter() == null)
    {
      throw (SFException) IncidentUtil.generateIncidentV2WithException(
          context.getSession(),
          new SFException(ErrorCode.INTERNAL_ERROR,
                          "missing date formatter"),
          null,
          null);
    }
    Date date = toDate(index);
    return date == null ? null :
           ResultUtil.getDateAsString(date, context.getDateFormatter());
  }

  @Override
  public Object toObject(int index) throws SFException
  {
    return toDate(index);
  }
}
{'fraction_non_alphanumeric': 0.09884678747940692, 'fraction_numerical': 0.00514827018121911, 'mean_word_length': 3.2161458333333335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6615729', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1474, 'n_words': 332}