Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.
*/
package com.hazelcast.org.apache.calcite.adapter.clone;
import com.hazelcast.org.apache.calcite.adapter.java.JavaTypeFactory;
import com.hazelcast.org.apache.calcite.avatica.ColumnMetaData;
import com.hazelcast.org.apache.calcite.avatica.util.DateTimeUtils;
import com.hazelcast.org.apache.calcite.linq4j.Enumerable;
import com.hazelcast.org.apache.calcite.linq4j.Ord;
import com.hazelcast.org.apache.calcite.linq4j.tree.Primitive;
import com.hazelcast.org.apache.calcite.rel.type.RelDataType;
import com.hazelcast.org.apache.calcite.rel.type.RelDataTypeField;
import com.hazelcast.org.apache.calcite.rel.type.RelProtoDataType;
import com.hazelcast.org.apache.calcite.util.Util;
import com.hazelcast.org.checkerframework.checker.nullness.qual.EnsuresNonNullIf;
import com.hazelcast.org.checkerframework.checker.nullness.qual.Nullable;
import java.lang.reflect.Type;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static java.util.Objects.requireNonNull;
/**
* Column loader.
*
* @param Element type of source table
*/
class ColumnLoader {
static final int[] INT_B = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000};
static final int[] INT_S = {1, 2, 4, 8, 16};
static final long[] LONG_B = {
0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000, 0xFFFFFFFF00000000L};
static final int[] LONG_S = {1, 2, 4, 8, 16, 32};
public final List list = new ArrayList<>();
public final List representationValues = new ArrayList<>();
private final JavaTypeFactory typeFactory;
public final int sortField;
/** Creates a column loader, and performs the load.
*
* @param typeFactory Type factory
* @param sourceTable Source data
* @param protoRowType Logical row type
* @param repList Physical row types, or null if not known */
@SuppressWarnings("method.invocation.invalid")
ColumnLoader(JavaTypeFactory typeFactory,
Enumerable sourceTable,
RelProtoDataType protoRowType,
@Nullable List repList) {
this.typeFactory = typeFactory;
final RelDataType rowType = protoRowType.apply(typeFactory);
if (repList == null) {
repList =
Collections.nCopies(rowType.getFieldCount(),
ColumnMetaData.Rep.OBJECT);
}
sourceTable.into(list);
final int[] sorts = {-1};
load(rowType, repList, sorts);
this.sortField = sorts[0];
}
static int nextPowerOf2(int v) {
v--;
v |= v >>> 1;
v |= v >>> 2;
v |= v >>> 4;
v |= v >>> 8;
v |= v >>> 16;
v++;
return v;
}
static long nextPowerOf2(long v) {
v--;
v |= v >>> 1;
v |= v >>> 2;
v |= v >>> 4;
v |= v >>> 8;
v |= v >>> 16;
v |= v >>> 32;
v++;
return v;
}
static int log2(int v) {
int r = 0;
for (int i = 4; i >= 0; i--) {
if ((v & INT_B[i]) != 0) {
v >>= INT_S[i];
r |= INT_S[i];
}
}
return r;
}
static int log2(long v) {
int r = 0;
for (int i = 5; i >= 0; i--) {
if ((v & LONG_B[i]) != 0) {
v >>= LONG_S[i];
r |= LONG_S[i];
}
}
return r;
}
static int[] invert(int[] targets) {
final int[] sources = new int[targets.length];
for (int i = 0; i < targets.length; i++) {
sources[targets[i]] = i;
}
return sources;
}
static boolean isIdentity(int[] sources) {
for (int i = 0; i < sources.length; i++) {
if (sources[i] != i) {
return false;
}
}
return true;
}
public int size() {
return list.size();
}
private void load(final RelDataType elementType,
List repList, int[] sort) {
final List types =
new AbstractList() {
final List fields =
elementType.getFieldList();
@Override public Type get(int index) {
return typeFactory.getJavaClass(
fields.get(index).getType());
}
@Override public int size() {
return fields.size();
}
};
int[] sources = null;
for (final Ord pair : Ord.zip(types)) {
@SuppressWarnings("unchecked")
final List> sliceList =
types.size() == 1
? list
: new AbstractList