package org.example;

// import org.elasticsearch.common.logging.ESLoggerFactory;

import org.apache.arrow.algorithm.sort.*;
import org.apache.arrow.memory.AllocationListener;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.*;
import org.apache.arrow.vector.complex.ListVector;
import org.apache.arrow.vector.complex.StructVector;
import org.apache.arrow.vector.types.Types;
import org.apache.arrow.vector.types.pojo.ArrowType;
import org.apache.arrow.vector.types.pojo.Field;
import org.apache.arrow.vector.types.pojo.FieldType;
import org.apache.arrow.vector.types.pojo.Schema;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Hello world!
 *
 */
public class App {

    public static void main( String[] args ) {
        RootAllocator rootAllocator = new RootAllocator(AllocationListener.NOOP, Long.MAX_VALUE);

        FieldType type = new FieldType(true, ArrowType.Struct.INSTANCE, null, null);
        StructVector structVector = new StructVector("struct", rootAllocator, type, null);

        IntVector intVector0 = structVector.addOrGet("int1", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class);
        intVector0.setSafe(0, 1);
        intVector0.setSafe(1, 1);
        intVector0.setSafe(2, 0);
        intVector0.setSafe(3, 0);
        intVector0.setValueCount(4);

        IntVector intVector1 = structVector.addOrGet("int2", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class);
        intVector1.setSafe(0, 4);
        intVector1.setSafe(1, 3);
        intVector1.setSafe(2, 2);
        intVector1.setSafe(3, 1);
        intVector1.setValueCount(4);

        VectorValueComparator vectorValueComparator0 = new DefaultVectorComparators.IntComparator();
        vectorValueComparator0.attachVector(intVector0);
        VectorValueComparator vectorValueComparator1 = new DefaultVectorComparators.IntComparator();
        vectorValueComparator1.attachVector(intVector1);
        VectorValueComparator[] vectorValueComparators = new VectorValueComparator[2];
        vectorValueComparators[0] = vectorValueComparator0;
        vectorValueComparators[1] = vectorValueComparator1;
        CompositeVectorComparator compositeVectorComparator = new CompositeVectorComparator(vectorValueComparators);

        StructVector structVectorDst = new StructVector("struct", rootAllocator, type, null);
        structVectorDst.allocateNew();
        structVectorDst.setValueCount(4);

        VariableWidthOutOfPlaceVectorSorter variableWidthOutOfPlaceVectorSorter = new VariableWidthOutOfPlaceVectorSorter();

        // This line doesn't compile because StructVector doesn't extend BaseVariableWidthVector
        variableWidthOutOfPlaceVectorSorter.sortOutOfPlace(structVector, structVectorDst, compositeVectorComparator);
    }
}
