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.rel.externalize;
import com.hazelcast.org.apache.calcite.avatica.AvaticaUtils;
import com.hazelcast.org.apache.calcite.avatica.util.TimeUnit;
import com.hazelcast.org.apache.calcite.plan.RelOptCluster;
import com.hazelcast.org.apache.calcite.rel.RelCollation;
import com.hazelcast.org.apache.calcite.rel.RelCollationImpl;
import com.hazelcast.org.apache.calcite.rel.RelCollations;
import com.hazelcast.org.apache.calcite.rel.RelDistribution;
import com.hazelcast.org.apache.calcite.rel.RelDistributions;
import com.hazelcast.org.apache.calcite.rel.RelFieldCollation;
import com.hazelcast.org.apache.calcite.rel.RelFieldCollation.Direction;
import com.hazelcast.org.apache.calcite.rel.RelFieldCollation.NullDirection;
import com.hazelcast.org.apache.calcite.rel.RelInput;
import com.hazelcast.org.apache.calcite.rel.RelNode;
import com.hazelcast.org.apache.calcite.rel.core.AggregateCall;
import com.hazelcast.org.apache.calcite.rel.core.CorrelationId;
import com.hazelcast.org.apache.calcite.rel.type.RelDataType;
import com.hazelcast.org.apache.calcite.rel.type.RelDataTypeFactory;
import com.hazelcast.org.apache.calcite.rel.type.RelDataTypeField;
import com.hazelcast.org.apache.calcite.rex.RexBuilder;
import com.hazelcast.org.apache.calcite.rex.RexCall;
import com.hazelcast.org.apache.calcite.rex.RexCorrelVariable;
import com.hazelcast.org.apache.calcite.rex.RexFieldAccess;
import com.hazelcast.org.apache.calcite.rex.RexFieldCollation;
import com.hazelcast.org.apache.calcite.rex.RexLiteral;
import com.hazelcast.org.apache.calcite.rex.RexNode;
import com.hazelcast.org.apache.calcite.rex.RexOver;
import com.hazelcast.org.apache.calcite.rex.RexSlot;
import com.hazelcast.org.apache.calcite.rex.RexWindow;
import com.hazelcast.org.apache.calcite.rex.RexWindowBound;
import com.hazelcast.org.apache.calcite.rex.RexWindowBounds;
import com.hazelcast.org.apache.calcite.sql.SqlAggFunction;
import com.hazelcast.org.apache.calcite.sql.SqlFunction;
import com.hazelcast.org.apache.calcite.sql.SqlIdentifier;
import com.hazelcast.org.apache.calcite.sql.SqlIntervalQualifier;
import com.hazelcast.org.apache.calcite.sql.SqlKind;
import com.hazelcast.org.apache.calcite.sql.SqlOperator;
import com.hazelcast.org.apache.calcite.sql.SqlSyntax;
import com.hazelcast.org.apache.calcite.sql.fun.SqlStdOperatorTable;
import com.hazelcast.org.apache.calcite.sql.parser.SqlParserPos;
import com.hazelcast.org.apache.calcite.sql.type.SqlTypeName;
import com.hazelcast.org.apache.calcite.sql.validate.SqlNameMatchers;
import com.hazelcast.org.apache.calcite.util.ImmutableBitSet;
import com.hazelcast.org.apache.calcite.util.ImmutableIntList;
import com.hazelcast.org.apache.calcite.util.JsonBuilder;
import com.hazelcast.org.apache.calcite.util.Util;
import com.hazelcast.com.google.common.collect.ImmutableList;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static com.hazelcast.org.apache.calcite.rel.RelDistributions.EMPTY;
/**
* Utilities for converting {@link com.hazelcast.org.apache.calcite.rel.RelNode}
* into JSON format.
*/
public class RelJson {
private final Map constructorMap = new HashMap<>();
private final JsonBuilder jsonBuilder;
public static final List PACKAGES =
ImmutableList.of(
"com.hazelcast.org.apache.calcite.rel.",
"com.hazelcast.org.apache.calcite.rel.core.",
"com.hazelcast.org.apache.calcite.rel.logical.",
"com.hazelcast.org.apache.calcite.adapter.jdbc.",
"com.hazelcast.org.apache.calcite.adapter.jdbc.JdbcRules$");
public RelJson(JsonBuilder jsonBuilder) {
this.jsonBuilder = jsonBuilder;
}
public RelNode create(Map map) {
String type = (String) map.get("type");
Constructor constructor = getConstructor(type);
try {
return (RelNode) constructor.newInstance(map);
} catch (InstantiationException | ClassCastException | InvocationTargetException
| IllegalAccessException e) {
throw new RuntimeException(
"while invoking constructor for type '" + type + "'", e);
}
}
public Constructor getConstructor(String type) {
Constructor constructor = constructorMap.get(type);
if (constructor == null) {
Class clazz = typeNameToClass(type);
try {
//noinspection unchecked
constructor = clazz.getConstructor(RelInput.class);
} catch (NoSuchMethodException e) {
throw new RuntimeException("class does not have required constructor, "
+ clazz + "(RelInput)");
}
constructorMap.put(type, constructor);
}
return constructor;
}
/**
* Converts a type name to a class. E.g. {@code getClass("LogicalProject")}
* returns {@link com.hazelcast.org.apache.calcite.rel.logical.LogicalProject}.class.
*/
public Class typeNameToClass(String type) {
if (!type.contains(".")) {
for (String package_ : PACKAGES) {
try {
return Class.forName(package_ + type);
} catch (ClassNotFoundException e) {
// ignore
}
}
}
try {
return Class.forName(type);
} catch (ClassNotFoundException e) {
throw new RuntimeException("unknown type " + type);
}
}
/**
* Inverse of {@link #typeNameToClass}.
*/
public String classToTypeName(Class extends RelNode> class_) {
final String canonicalName = class_.getName();
for (String package_ : PACKAGES) {
if (canonicalName.startsWith(package_)) {
String remaining = canonicalName.substring(package_.length());
if (remaining.indexOf('.') < 0 && remaining.indexOf('$') < 0) {
return remaining;
}
}
}
return canonicalName;
}
public Object toJson(RelCollationImpl node) {
final List