Creates a column descriptor for sate column family.

<p>Sets TTL compaction filter if {@code ttlCompactFiltersManager} is not {@code null}.
345219
public static ColumnFamilyDescriptor createColumnFamilyDescriptor(
		RegisteredStateMetaInfoBase metaInfoBase,
		Function<String, ColumnFamilyOptions> columnFamilyOptionsFactory,
		@Nullable RocksDbTtlCompactFiltersManager ttlCompactFiltersManager) {

		ColumnFamilyOptions options = createColumnFamilyOptions(columnFamilyOptionsFactory, metaInfoBase.getName());
		if (ttlCompactFiltersManager != null) {
			ttlCompactFiltersManager.setAndRegisterCompactFilterIfStateTtl(metaInfoBase, options);
		}
		byte[] nameBytes = metaInfoBase.getName().getBytes(ConfigConstants.DEFAULT_CHARSET);
		Preconditions.checkState(!Arrays.equals(RocksDB.DEFAULT_COLUMN_FAMILY, nameBytes),
			"The chosen state name 'default' collides with the name of the default column family!");

		return new ColumnFamilyDescriptor(nameBytes, options);
	}
408493
public static EvaluatorDescriptorInfo toEvaluatorDescriptorInfo(
      final EvaluatorDescriptor descriptor) {
    if (descriptor == null) {
      return null;
    }
    EvaluatorDescriptorInfo.NodeDescriptorInfo nodeDescriptorInfo = descriptor.getNodeDescriptor() == null ? null :
        EvaluatorDescriptorInfo.NodeDescriptorInfo.newBuilder()
            .setHostName(descriptor.getNodeDescriptor().getName())
            .setId(descriptor.getNodeDescriptor().getId())
            .setIpAddress(descriptor.getNodeDescriptor().getInetSocketAddress().getAddress().getHostAddress())
            .setPort(descriptor.getNodeDescriptor().getInetSocketAddress().getPort())
            .setRackName(descriptor.getNodeDescriptor().getRackDescriptor() == null ?
                "" : descriptor.getNodeDescriptor().getRackDescriptor().getName())
            .build();
    return EvaluatorDescriptorInfo.newBuilder()
        .setCores(descriptor.getNumberOfCores())
        .setMemory(descriptor.getMemory())
        .setRuntimeName(descriptor.getRuntimeName())
        .setNodeDescriptorInfo(nodeDescriptorInfo)
        .build();
  }
118181
@Override
    public void createTableIfDoesNotExist(final String tableName, final String... colFamily)
            throws MasterNotRunningException, IOException
    {
        if (!admin.tableExists(Bytes.toBytes(tableName)))
        {
            HTableDescriptor htDescriptor = new HTableDescriptor(TableName.valueOf(tableName));
            for (String columnFamily : colFamily)
            {
                HColumnDescriptor familyMetadata = new HColumnDescriptor(columnFamily);
                htDescriptor.addFamily(familyMetadata);
            }
            admin.createTable(htDescriptor);
        }
    }
690501
@Nullable
    static ColumnMetadata buildColumnMetadata(@NotNull PropertyDescriptor propertyDescriptor,
                                              @NotNull Class clazz,
                                              @NotNull CassandraClient cassandraClient,
                                              @NotNull TableMetadata tableMetadata) {

        try {
            Field field = clazz.getDeclaredField(propertyDescriptor.getName());

            if (field.isAnnotationPresent(Column.class)) {

                Column columnAnnotation = field.getDeclaredAnnotation(Column.class);

                String columnName = getColumnName(propertyDescriptor, columnAnnotation);

                ColumnMetadata columnMetadata = new BaseColumnMetadata(propertyDescriptor, clazz, field.getType(), columnName, tableMetadata.getColumn(columnName).getType());

                if (field.isAnnotationPresent(Enumerated.class)) {
                    Enumerated enumeratedAnnotation = field.getDeclaredAnnotation(Enumerated.class);

                    columnMetadata = new EnumeratedMetadata(columnMetadata, enumeratedAnnotation.enumType());
                }
                if (field.isAnnotationPresent(UDTColumn.class)) {
                    UDTColumn udtColumnAnnotation = field.getDeclaredAnnotation(UDTColumn.class);

                    Class udtClassType = udtColumnAnnotation.udtType();

                    if (udtClassType.isAnnotationPresent(UDT.class)) {
                        UDT declaredAnnotation = (UDT) udtClassType.getDeclaredAnnotation(UDT.class);

                        String keyspace = StringUtils.isEmpty(declaredAnnotation.keyspace()) ? cassandraClient.getDefaultKeyspace() : declaredAnnotation.keyspace();

                        UserType userType = cassandraClient.getKeyspaceMetadata(keyspace)
                                                           .getUserType(declaredAnnotation.name());

                        Verify.verifyNotNull(userType);

                        columnMetadata = new UserDataTypeMetadata(udtColumnAnnotation.udtType(), userType, columnMetadata);
                    }


                }

                if (field.isAnnotationPresent(PrimaryKey.class)) {
                    PrimaryKey primaryKeyAnnotation = field.getDeclaredAnnotation(PrimaryKey.class);
                    columnMetadata = new PrimaryKeyMetadata(columnMetadata, primaryKeyAnnotation.order(), primaryKeyAnnotation.isPartitionKey());
                }


                return columnMetadata;
            }
        } catch (NoSuchFieldException e) {
            if (!StringUtils.equals("class", propertyDescriptor.getDisplayName())) {
                LOGGER.warn("Can't get field", e);
            }
        }

        return null;
    }
131903
private void addColumnFamilyAndSetProperties(HTableDescriptor tableDescriptor, String colFamilyName)
    {
        if (!tableDescriptor.hasFamily(colFamilyName.getBytes()))
        {
            HColumnDescriptor hColumnDescriptor = getColumnDescriptor(colFamilyName);
            tableDescriptor.addFamily(hColumnDescriptor);
            setExternalProperties(tableDescriptor.getNameAsString(), hColumnDescriptor);
        }
    }
1124088
public static FilterAdapter buildAdapter() {
    FilterAdapter adapter = new FilterAdapter();
    adapter.addFilterAdapter(
        ColumnPrefixFilter.class, new ColumnPrefixFilterAdapter());
    adapter.addFilterAdapter(
        ColumnRangeFilter.class, new ColumnRangeFilterAdapter());
    adapter.addFilterAdapter(
        KeyOnlyFilter.class, new KeyOnlyFilterAdapter());
    adapter.addFilterAdapter(
        MultipleColumnPrefixFilter.class, new MultipleColumnPrefixFilterAdapter());
    adapter.addFilterAdapter(
        TimestampsFilter.class, new TimestampsFilterAdapter());
    adapter.addFilterAdapter(
      TimestampRangeFilter.class, new TimestampRangeFilterAdapter());
    ValueFilterAdapter valueFilterAdapter = new ValueFilterAdapter();
    adapter.addFilterAdapter(
        ValueFilter.class, valueFilterAdapter);
    SingleColumnValueFilterAdapter scvfa =
        new SingleColumnValueFilterAdapter(valueFilterAdapter);
    adapter.addFilterAdapter(
        SingleColumnValueFilter.class, scvfa);
    adapter.addFilterAdapter(
        SingleColumnValueExcludeFilter.class,
        new SingleColumnValueExcludeFilterAdapter(scvfa));
    adapter.addFilterAdapter(
        ColumnPaginationFilter.class, new ColumnPaginationFilterAdapter());
    adapter.addFilterAdapter(
        FirstKeyOnlyFilter.class, new FirstKeyOnlyFilterAdapter());
    adapter.addFilterAdapter(
        ColumnCountGetFilter.class, new ColumnCountGetFilterAdapter());
    adapter.addFilterAdapter(
        RandomRowFilter.class, new RandomRowFilterAdapter());
    adapter.addFilterAdapter(
        PrefixFilter.class, new PrefixFilterAdapter());
    adapter.addFilterAdapter(
        QualifierFilter.class, new QualifierFilterAdapter());
    adapter.addFilterAdapter(
        PageFilter.class, new PageFilterAdapter());
    adapter.addFilterAdapter(
      WhileMatchFilter.class, new WhileMatchFilterAdapter(adapter));
    adapter.addFilterAdapter(
        org.apache.hadoop.hbase.filter.RowFilter.class, new RowFilterAdapter());
    adapter.addFilterAdapter(FuzzyRowFilter.class, new FuzzyRowFilterAdapter());
    adapter.addFilterAdapter(FamilyFilter.class, new FamilyFilterAdapter());
    adapter.addFilterAdapter(BigtableFilter.class, new BigtableFilterAdapter());

    // MultiRowRangeFilter only exists in hbase >= 1.1
    try {
      adapter.addFilterAdapter(
          org.apache.hadoop.hbase.filter.MultiRowRangeFilter.class,
          new MultiRowRangeFilterAdapter()
      );
    } catch (NoClassDefFoundError ignored) {
    }

    // Passing the FilterAdapter in to the FilterListAdapter is a bit
    // unfortunate, but makes adapting the FilterList's subfilters simpler.
    FilterListAdapter filterListAdapter = new FilterListAdapter(adapter);
    // FilterList implements UnsupportedStatusCollector so it should
    // be used when possible (third parameter to addFilterAdapter()).
    adapter.addFilterAdapter(
        FilterList.class, filterListAdapter, filterListAdapter);

    return adapter;
  }
10186
public static <T> TableSource<T> findAndCreateTableSource(Descriptor descriptor) {
		Map<String, String> properties = descriptor.toProperties();

		TableSource tableSource;
		try {
			tableSource = TableFactoryService
				.find(TableSourceFactory.class, properties)
				.createTableSource(properties);
		} catch (Throwable t) {
			throw new TableException("findAndCreateTableSource failed.", t);
		}

		return tableSource;
	}
766987
public static Map<String, String> getUnsupportedFeatures(HColumnDescriptor columnDescriptor) {
    Map<String, String> unsupportedConfiguration = new HashMap<String, String>();

    Map<String, String> configuration = columnDescriptor.getConfiguration();
    for (Map.Entry<String, String> entry : SUPPORTED_OPTION_VALUES.entrySet()) {
      if (configuration.containsKey(entry.getKey())
          && configuration.get(entry.getKey()) != null
          && !entry.getValue().equals(configuration.get(entry.getKey()))) {
        unsupportedConfiguration.put(entry.getKey(), configuration.get(entry.getKey()));
      }
    }
    return unsupportedConfiguration;
  }
507411
public static List<ListViewColumn> createDefaultInitialColumnList(View view) {
        return createDefaultInitialColumnList(DescriptorVisibilityFilter.apply(view, ListViewColumn.all()));
    }
673788
private Filter getFilter(final String columnFamily)
    {
        FilterList filter = filters.get(columnFamily);
        if (filter == null)
        {
            return this.filter;
        }
        if (this.filter != null)
        {
            filter.addFilter(this.filter);
        }
        return filter;
    }
579314
private Filter createStateFilter() {
    byte[] processedMask = new byte[Ints.BYTES * 2 + 1];
    processedMask[processedMask.length - 1] = ConsumerEntryState.PROCESSED.getState();
    return new SingleColumnValueFilter(QueueEntryRow.COLUMN_FAMILY, stateColumnName,
                                       CompareFilter.CompareOp.NOT_EQUAL,
                                       new BitComparator(processedMask, BitComparator.BitwiseOp.AND));
  }
1196942
private void reduceNameFilter(QueryFilter filter, ColumnFamily container, long sstableTimestamp)
    {
        if (container == null)
            return;

        for (Iterator<CellName> iterator = ((NamesQueryFilter) filter.filter).columns.iterator(); iterator.hasNext(); )
        {
            CellName filterColumn = iterator.next();
            Cell cell = container.getColumn(filterColumn);
            if (cell != null && cell.timestamp() > sstableTimestamp)
                iterator.remove();
        }
    }
884150
private ColumnTypeDescriptor getColumnTypeDescriptor(ColumnDataType columnDataType, Map<String, ColumnTypeDescriptor> columnTypes, Store store) {
        String databaseSpecificTypeName = columnDataType.getDatabaseSpecificTypeName();
        ColumnTypeDescriptor columnTypeDescriptor = columnTypes.get(databaseSpecificTypeName);
        if (columnTypeDescriptor == null) {
            columnTypeDescriptor = store.find(ColumnTypeDescriptor.class, databaseSpecificTypeName);
            if (columnTypeDescriptor == null) {
                columnTypeDescriptor = store.create(ColumnTypeDescriptor.class);
                columnTypeDescriptor.setDatabaseType(databaseSpecificTypeName);
                columnTypeDescriptor.setAutoIncrementable(columnDataType.isAutoIncrementable());
                columnTypeDescriptor.setCaseSensitive(columnDataType.isCaseSensitive());
                columnTypeDescriptor.setPrecision(columnDataType.getPrecision());
                columnTypeDescriptor.setMinimumScale(columnDataType.getMinimumScale());
                columnTypeDescriptor.setMaximumScale(columnDataType.getMaximumScale());
                columnTypeDescriptor.setFixedPrecisionScale(columnDataType.isFixedPrecisionScale());
                columnTypeDescriptor.setNumericPrecisionRadix(columnDataType.getNumPrecisionRadix());
                columnTypeDescriptor.setUnsigned(columnDataType.isUnsigned());
                columnTypeDescriptor.setUserDefined(columnDataType.isUserDefined());
                columnTypeDescriptor.setNullable(columnDataType.isNullable());
            }
            columnTypes.put(databaseSpecificTypeName, columnTypeDescriptor);
        }
        return columnTypeDescriptor;
    }
385653
@Nullable
  private static DimFilter toSimpleLeafFilter(
      final PlannerContext plannerContext,
      final DruidQuerySignature querySignature,
      final RexNode rexNode
  )
  {
    final SqlKind kind = rexNode.getKind();

    if (kind == SqlKind.IS_TRUE || kind == SqlKind.IS_NOT_FALSE) {
      return toSimpleLeafFilter(
          plannerContext,
          querySignature,
          Iterables.getOnlyElement(((RexCall) rexNode).getOperands())
      );
    } else if (kind == SqlKind.IS_FALSE || kind == SqlKind.IS_NOT_TRUE) {
      return new NotDimFilter(
          toSimpleLeafFilter(
              plannerContext,
              querySignature,
              Iterables.getOnlyElement(((RexCall) rexNode).getOperands())
          )
      );
    } else if (kind == SqlKind.IS_NULL || kind == SqlKind.IS_NOT_NULL) {
      final RexNode operand = Iterables.getOnlyElement(((RexCall) rexNode).getOperands());

      // operand must be translatable to a SimpleExtraction to be simple-filterable
      final DruidExpression druidExpression =
          toDruidExpression(plannerContext, querySignature.getRowSignature(), operand);

      if (druidExpression == null) {
        return null;
      }

      final DimFilter equalFilter;
      if (druidExpression.isSimpleExtraction()) {
        equalFilter = new SelectorDimFilter(
            druidExpression.getSimpleExtraction().getColumn(),
            NullHandling.defaultStringValue(),
            druidExpression.getSimpleExtraction().getExtractionFn()
        );
      } else {
        final VirtualColumn virtualColumn = querySignature.getOrCreateVirtualColumnForExpression(
            plannerContext,
            druidExpression,
            operand.getType().getSqlTypeName()
        );
        if (virtualColumn == null) {
          return null;
        }
        equalFilter = new SelectorDimFilter(
            virtualColumn.getOutputName(),
            NullHandling.defaultStringValue(),
            null
        );
      }

      return kind == SqlKind.IS_NOT_NULL ? new NotDimFilter(equalFilter) : equalFilter;
    } else if (kind == SqlKind.EQUALS
               || kind == SqlKind.NOT_EQUALS
               || kind == SqlKind.GREATER_THAN
               || kind == SqlKind.GREATER_THAN_OR_EQUAL
               || kind == SqlKind.LESS_THAN
               || kind == SqlKind.LESS_THAN_OR_EQUAL) {
      final List<RexNode> operands = ((RexCall) rexNode).getOperands();
      Preconditions.checkState(operands.size() == 2, "WTF?! Expected 2 operands, got[%,d]", operands.size());
      boolean flip = false;
      RexNode lhs = operands.get(0);
      RexNode rhs = operands.get(1);

      if (lhs.getKind() == SqlKind.LITERAL && rhs.getKind() != SqlKind.LITERAL) {
        // swap lhs, rhs
        RexNode x = lhs;
        lhs = rhs;
        rhs = x;
        flip = true;
      }

      // Flip operator, maybe.
      final SqlKind flippedKind;

      if (flip) {
        switch (kind) {
          case EQUALS:
          case NOT_EQUALS:
            flippedKind = kind;
            break;
          case GREATER_THAN:
            flippedKind = SqlKind.LESS_THAN;
            break;
          case GREATER_THAN_OR_EQUAL:
            flippedKind = SqlKind.LESS_THAN_OR_EQUAL;
            break;
          case LESS_THAN:
            flippedKind = SqlKind.GREATER_THAN;
            break;
          case LESS_THAN_OR_EQUAL:
            flippedKind = SqlKind.GREATER_THAN_OR_EQUAL;
            break;
          default:
            throw new ISE("WTF?! Kind[%s] not expected here", kind);
        }
      } else {
        flippedKind = kind;
      }

      // rhs must be a literal
      if (rhs.getKind() != SqlKind.LITERAL) {
        return null;
      }

      // Translate lhs to a DruidExpression.
      final DruidExpression lhsExpression = toDruidExpression(plannerContext, querySignature.getRowSignature(), lhs);
      if (lhsExpression == null) {
        return null;
      }

      // Special handling for filters on FLOOR(__time TO granularity).
      final Granularity queryGranularity = toQueryGranularity(lhsExpression, plannerContext.getExprMacroTable());
      if (queryGranularity != null) {
        // lhs is FLOOR(__time TO granularity); rhs must be a timestamp
        final long rhsMillis = Calcites.calciteDateTimeLiteralToJoda(rhs, plannerContext.getTimeZone()).getMillis();
        return buildTimeFloorFilter(ColumnHolder.TIME_COLUMN_NAME, queryGranularity, flippedKind, rhsMillis);
      }

      final String column;
      final ExtractionFn extractionFn;
      if (lhsExpression.isSimpleExtraction()) {
        column = lhsExpression.getSimpleExtraction().getColumn();
        extractionFn = lhsExpression.getSimpleExtraction().getExtractionFn();
      } else {
        VirtualColumn virtualLhs = querySignature.getOrCreateVirtualColumnForExpression(
            plannerContext,
            lhsExpression,
            lhs.getType().getSqlTypeName()
        );
        if (virtualLhs == null) {
          return null;
        }
        column = virtualLhs.getOutputName();
        extractionFn = null;
      }

      if (column.equals(ColumnHolder.TIME_COLUMN_NAME) && extractionFn instanceof TimeFormatExtractionFn) {
        // Check if we can strip the extractionFn and convert the filter to a direct filter on __time.
        // This allows potential conversion to query-level "intervals" later on, which is ideal for Druid queries.

        final Granularity granularity = ExtractionFns.toQueryGranularity(extractionFn);
        if (granularity != null) {
          // lhs is FLOOR(__time TO granularity); rhs must be a timestamp
          final long rhsMillis = Calcites.calciteDateTimeLiteralToJoda(rhs, plannerContext.getTimeZone()).getMillis();
          final Interval rhsInterval = granularity.bucket(DateTimes.utc(rhsMillis));

          // Is rhs aligned on granularity boundaries?
          final boolean rhsAligned = rhsInterval.getStartMillis() == rhsMillis;

          // Create a BoundRefKey that strips the extractionFn and compares __time as a number.
          final BoundRefKey boundRefKey = new BoundRefKey(column, null, StringComparators.NUMERIC);

          return getBoundTimeDimFilter(flippedKind, boundRefKey, rhsInterval, rhsAligned);
        }
      }

      final String val;
      final RexLiteral rhsLiteral = (RexLiteral) rhs;
      if (SqlTypeName.NUMERIC_TYPES.contains(rhsLiteral.getTypeName())) {
        val = String.valueOf(RexLiteral.value(rhsLiteral));
      } else if (SqlTypeName.CHAR_TYPES.contains(rhsLiteral.getTypeName())) {
        val = String.valueOf(RexLiteral.stringValue(rhsLiteral));
      } else if (SqlTypeName.TIMESTAMP == rhsLiteral.getTypeName() || SqlTypeName.DATE == rhsLiteral.getTypeName()) {
        val = String.valueOf(
            Calcites.calciteDateTimeLiteralToJoda(
                rhsLiteral,
                plannerContext.getTimeZone()
            ).getMillis()
        );
      } else {
        // Don't know how to filter on this kind of literal.
        return null;
      }

      // Numeric lhs needs a numeric comparison.
      final StringComparator comparator = Calcites.getStringComparatorForSqlTypeName(lhs.getType().getSqlTypeName());
      final BoundRefKey boundRefKey = new BoundRefKey(column, extractionFn, comparator);
      final DimFilter filter;

      // Always use BoundDimFilters, to simplify filter optimization later (it helps to remember the comparator).
      switch (flippedKind) {
        case EQUALS:
          filter = Bounds.equalTo(boundRefKey, val);
          break;
        case NOT_EQUALS:
          filter = new NotDimFilter(Bounds.equalTo(boundRefKey, val));
          break;
        case GREATER_THAN:
          filter = Bounds.greaterThan(boundRefKey, val);
          break;
        case GREATER_THAN_OR_EQUAL:
          filter = Bounds.greaterThanOrEqualTo(boundRefKey, val);
          break;
        case LESS_THAN:
          filter = Bounds.lessThan(boundRefKey, val);
          break;
        case LESS_THAN_OR_EQUAL:
          filter = Bounds.lessThanOrEqualTo(boundRefKey, val);
          break;
        default:
          throw new IllegalStateException("WTF?! Shouldn't have got here...");
      }

      return filter;
    } else if (rexNode instanceof RexCall) {
      final SqlOperator operator = ((RexCall) rexNode).getOperator();

      final SqlOperatorConversion conversion =
          plannerContext.getOperatorTable().lookupOperatorConversion(operator);

      if (conversion == null) {
        return null;
      } else {
        DimFilter filter =
            conversion.toDruidFilter(plannerContext, querySignature, rexNode);
        if (filter != null) {
          return filter;
        }
        return null;
      }
    }
    return null;
  }
1249084
@Override
    protected FilterChainResolver createFilterChainResolver() {

        FilterChainResolver originalFilterChainResolver = super.createFilterChainResolver();

        if (originalFilterChainResolver == null) {
            return null;
        }

        return getFilterChainResolverFactory(originalFilterChainResolver).getInstance();
    }
1132970
public static <T> TableSink<T> findAndCreateTableSink(Descriptor descriptor) {
		Map<String, String> properties = descriptor.toProperties();

		TableSink tableSink;
		try {
			tableSink = TableFactoryService
				.find(TableSinkFactory.class, properties)
				.createTableSink(properties);
		} catch (Throwable t) {
			throw new TableException("findAndCreateTableSink failed.", t);
		}

		return tableSink;
	}
791889
private void createAndSetFilter(final Scanner scanner) {
    QueryUtil.setDataTableScanFilter(scanner, group_bys, row_key_literals, 
        explicit_tags, enable_fuzzy_filter, 
        (end_time == UNSET
        ? -1  // Will scan until the end (0xFFF...).
        : (int) getScanEndTimeSeconds()));
  }