func (d *Driver) Create(
	db, table, id string,
	expressions []sql.Expression,
	config map[string]string,
) (sql.Index, error) {
	_, err := mkdir(d.root, db, table, id)
	if err != nil {
		return nil, err
	}
	if config == nil {
		config = make(map[string]string)
	}
	exprs := make([]string, len(expressions))
	for i, e := range expressions {
		exprs[i] = e.String()
	}
	cfg := index.NewConfig(db, table, id, exprs, d.ID(), config)
	err = index.WriteConfigFile(d.configFilePath(db, table, id), cfg)
	if err != nil {
		return nil, errWriteConfigFile.Wrap(err)
	}
	idx, err := d.newPilosaIndex(db, table)
	if err != nil {
		return nil, err
	}
	processingFile := d.processingFilePath(db, table, id)
	if err := index.WriteProcessingFile(
		processingFile,
		[]byte{processingFileOnCreate},
	); err != nil {
		return nil, errWriteConfigFile.Wrap(err)
	}
	return newPilosaIndex(idx, cfg), nil
}
Create a new index.
package pilosa
import (
	"context"
	"crypto/sha1"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"path/filepath"
	"runtime"
	"strconv"
	"strings"
	"sync"
	"sync/atomic"
	"time"
	"github.com/go-kit/kit/metrics/discard"
	opentracing "github.com/opentracing/opentracing-go"
	pilosa "github.com/pilosa/pilosa"
	"github.com/pilosa/pilosa/syswrap"
	"github.com/sirupsen/logrus"
	"github.com/src-d/go-mysql-server/sql"
	"github.com/src-d/go-mysql-server/sql/index"
	errors "gopkg.in/src-d/go-errors.v1"
)
const (
	DriverID = "pilosa"
	IndexNamePrefix = "idx"
	FieldNamePrefix = "fld"
	ConfigFileName = "config.yml"
	ProcessingFileName = ".processing"
	MappingFileNamePrefix = "map"
	MappingFileNameExtension = ".db"
)
const (
	processingFileOnCreate = 'C'
	processingFileOnSave   = 'S'
)
var (
	errCorruptedIndex   = errors.NewKind("the index db: %s, table: %s, id: %s is corrupted")
	errInvalidIndexType = errors.NewKind("expecting a pilosa index, instead got %T")
)
const (
	pilosaIndexThreadsKey = "PILOSA_INDEX_THREADS"
	pilosaIndexThreadsVar = "pilosa_index_threads"
)
type (
	bitBatch struct {
		size uint64
		rows []uint64
		cols []uint64
		pos  uint64
	}
	batch struct {
		bitBatches  []*bitBatch
		fields      []*pilosa.Field
		timePilosa  time.Duration
		timeMapping time.Duration
	}
	Driver struct {
		root string
	}
)
var (
	RowsGauge = discard.NewGauge()
	TotalHistogram = discard.NewHistogram()
	MappingHistogram = discard.NewHistogram()
	BitmapHistogram = discard.NewHistogram()
)
func NewDriver(root string) *Driver {
	return &Driver{
		root: root,
	}
}
func (*Driver) ID() string {
	return DriverID
}
var errWriteConfigFile = errors.NewKind("unable to write indexes configuration file")